package com.uzai.console.service.pyq.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import com.uzai.common.dto.base.BizLog;
import com.uzai.common.dto.pyq.FeedMedia;
import com.uzai.common.enums.*;
import com.uzai.common.exception.BusinessException;
import com.uzai.common.msg.MsgDto;
import com.uzai.common.result.ResponseCode;
import com.uzai.common.utils.EsIndexName;
import com.uzai.common.utils.RegularUtil;
import com.uzai.console.common.UzaiRespVo;
import com.uzai.console.common.utils.*;
import com.uzai.console.config.UzaiConsoleSysConfig;
import com.uzai.console.constant.Const;
import com.uzai.console.constant.ES.ElasticsearchUtilGroupMsg;
import com.uzai.console.dto.device.DeviceQuery;
import com.uzai.console.dto.feign.alarm.AlarmMsgFeignDto;
import com.uzai.console.dto.feign.turnlink.GenerateShortUrlDto;
import com.uzai.console.dto.feign.turnlink.SimpleTurnLinkDto;
import com.uzai.console.dto.feign.uzaimanage.SysRunlogWarningDto;
import com.uzai.console.dto.pyq.gfkgoods.PyqGfkGoodsQuery;
import com.uzai.console.dto.pyq.hdkgoods.PyqHdkGoodsQuery;
import com.uzai.console.dto.pyq.llygoods.PyqLlyGoodsUserIdDto;
import com.uzai.console.dto.pyq.pyqmaterial.TurnlinkDto;
import com.uzai.console.dto.rocketmq.pyq.PostSnsCommentDto;
import com.uzai.console.entity.*;
import com.uzai.console.entity.es.PyqJobDetail;
import com.uzai.console.mapper.*;
import com.uzai.console.service.device.DeviceService;
import com.uzai.console.service.feign.UzaiBroadcastFeignService;
import com.uzai.console.service.feign.UzaiBusinessFeignService;
import com.uzai.console.service.feign.UzaiManageFeignService;
import com.uzai.console.service.feign.UzaiTurnlinkFeignService;
import com.uzai.console.service.feign.dto.GoodsUpdateExposureNumBySendPyqDto;
import com.uzai.console.service.feign.dto.LlyGoodsPageDto;
import com.uzai.console.service.feign.dto.StopGoodsDto;
import com.uzai.console.service.merchant.MerchantService;
import com.uzai.console.service.pyq.PyqAutoSendService;
import com.uzai.console.service.pyq.PyqJobDetailService;
import com.uzai.console.service.ratelimit.RatelimitService;
import com.uzai.console.service.rocketmq.impl.NoticeMsgPushProducerServiceImpl;
import com.uzai.console.vo.device.DeviceInfoVo;
import com.uzai.console.vo.feign.turnlink.SimpleTurnlinkVo;
import com.uzai.console.vo.lly.LlyMiddleDetail;
import com.uzai.console.vo.pyq.llygoods.PyqLlyGoodsUserVo;
import com.uzai.console.vo.pyq.llygoods.PyqLlyGoodsVo;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.*;

/**
 * 朋友圈自动发送
 * @author liuqi
 * @date 2021年08月13日 11:34
 */
@Service
public class PyqAutoSendServiceImpl implements PyqAutoSendService {

    Logger logger = LoggerFactory.getLogger(PyqAutoSendServiceImpl.class);

    @Autowired
    private PyqAutoConfigMapper pyqAutoConfigMapper;
    @Autowired
    private PyqDevicePlanMapper pyqDevicePlanMapper;
    @Autowired
    private DeviceWechatInfoMapper deviceWechatInfoMapper;
    @Autowired
    private PyqAutoSendMapper pyqAutoSendMapper;
    @Autowired
    private PyqHdkGoodsMapper pyqHdkGoodsMapper;
    @Autowired
    private PyqGfkGoodsMapper pyqGfkGoodsMapper;
    @Autowired
    private PyqExpressionMapper pyqExpressionMapper;
    @Autowired
    private UzaiBroadcastFeignService uzaiBroadcastFeignService;
    @Autowired
    private PyqJobMapper pyqJobMapper;
    @Autowired
    private PyqFollowContentMapper pyqFollowContentMapper;
    @Autowired
    private PyqFollowCommentMapper pyqFollowCommentMapper;
    @Autowired
    private PyqJobDetailService pyqJobDetailService;
    @Autowired
    private NoticeMsgPushProducerServiceImpl noticeMsgPushProducerService;
    @Autowired
    private ElasticsearchUtilGroupMsg elasticsearchUtilGroupMsg;
    @Autowired
    private SysDomainMapper sysDomainMapper;
    @Autowired
    private UzaiConsoleSysConfig uzaiConsoleSysConfig;
    @Autowired
    private PyqLlyShortlinkMapper pyqLlyShortlinkMapper;
    @Autowired
    private PyqLlyGoodsMapper pyqLlyGoodsMapper;
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private UzaiTurnlinkFeignService uzaiTurnlinkFeignService;
    @Autowired
    private MerchantService merchantService;
    @Autowired
    private UzaiBusinessFeignService uzaiBusinessFeignService;
    @Autowired
    private ConfigPlanMapper configPlanMapper;
    @Autowired
    private TbTokenMapper tbTokenMapper;
    @Autowired
    private UzaiManageFeignService uzaiManageFeignService;
    @Autowired
    private RatelimitService ratelimitService;
    @Autowired
    private DeviceService deviceService;

    /**
     * 自动发送朋友圈
     * @author lucher
     * @date 2022/9/19 14:05
     * @param pyqAutoConfig
     */
    public void autoSendPyq(PyqAutoConfig pyqAutoConfig){

        if(pyqAutoConfig == null){
            throw  new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "自动发圈配置不存在");
        }

        if(pyqAutoConfig.getDevicePlanId() == null){
            throw  new BusinessException(ResponseCode.PARAMETER_EXCEPTION, "请选择设备方案");
        }

        PyqDevicePlan pyqDevicePlan = pyqDevicePlanMapper.selectById(pyqAutoConfig.getDevicePlanId(), pyqAutoConfig.getMerId());
        if(pyqDevicePlan == null){
            throw  new BusinessException(ResponseCode.PARAMETER_EXCEPTION, "请选择的设备方案不存在");
        }

        if(pyqDevicePlan.getDeviceModel() == null){
            throw  new BusinessException(ResponseCode.PARAMETER_EXCEPTION, "请选择发送机器人模式");
        }

        //发送朋友圈的机器人列表
        List<Long> deviceUniqueIdList = null;
        if(pyqDevicePlan.getDeviceModel().intValue() == 0){ //发送部分机器人模式
            //验证发送机器人
            deviceUniqueIdList = JSONObject.parseArray(pyqDevicePlan.getDeviceInfo(), Long.class);
        }else if(pyqDevicePlan.getDeviceModel().intValue() ==1){ //全部机器人
            DeviceQuery deviceQuery = new DeviceQuery();
            deviceQuery.setMerId(pyqAutoConfig.getMerId());
            deviceQuery.setDeviceType(pyqDevicePlan.getDeviceType());
            List<DeviceInfoVo> deviceList = deviceService.findDeviceList(deviceQuery);
            if(deviceList != null && deviceList.size() > 0){
                deviceUniqueIdList = new ArrayList<>();
                for (DeviceInfoVo deviceInfoVo : deviceList){
                    deviceUniqueIdList.add(deviceInfoVo.getId());
                }
            }
        }

        //循环机器人，查询机器人发送记录
        if(deviceUniqueIdList != null && deviceUniqueIdList.size() > 0){

            //记录最后一个发送明细
            PyqJobDetail pyqJobDetail_job = null;
            //主任务Id
            Long pyqJobId = IdWorker.getId();
            //现在时间
            int now = DateUtil.getNowTime() + 5; //发送时间延迟5秒
            //记录子任务明细数
            int totalCount = 0;
            //朋友圈类型 0商品 1图文 2-老林云
            Integer type = Tools.getInteger(pyqAutoConfig.getType());
            if(type.intValue() == 0){ //好单库商品

                //新的发送时间
                Integer sendTime_new = pyqAutoConfig.getSendTime();
                //新的发送时间天格式
                String sendTime_new_yyyyMMdd = Tools.getDateFormat(new Date(sendTime_new.intValue() * 1000L), "yyyy-MM-dd");

                for(Long deviceUniqueId : deviceUniqueIdList){
                    try {
                        //封装已经发送的商品列表
                        List<Long> goodsIdList = new ArrayList<>();

                        //获取每个机器人的已经发送的商品信息
                        //List<PyqAutoSend> pyqAutoSendList = pyqAutoSendMapper.selectByDeviceUniqueIdAndType(deviceUniqueId, type);
                        Integer limitRepeatDay = pyqAutoConfig.getLimitRepeatDay();
                        if(limitRepeatDay == null){
                            limitRepeatDay = 3; //默认为3天
                        }
                        Integer sendTime = Tools.getInteger(pyqAutoConfig.getSendTime()); //查询任务的最新发送时间
                        //不重复发送时间=最新时间-不重复发送限制时间
                        Integer limitRepeatTime =  sendTime - limitRepeatDay * 24 * 3600;
                        List<PyqAutoSend> pyqAutoSendList = pyqAutoSendMapper.selectByDeviceUniqueIdAndAutoConfigIdAndSendTime(deviceUniqueId, pyqAutoConfig.getId(), limitRepeatTime);
                        if(pyqAutoSendList != null){
                            for (PyqAutoSend pyqAutoSend : pyqAutoSendList){
                                goodsIdList.add(pyqAutoSend.getGoodsid());
                            }
                        }

                        //查询该机器人将要发送的最新的好单库商品
                        PyqHdkGoods pyqHdkGoods = null;
                        //不启用随机商品，就查询数据库最新商品
                        if(Tools.getInteger(pyqAutoConfig.getRandomImg()).intValue() == 0){
                            pyqHdkGoods = pyqHdkGoodsMapper.selectNewest(sendTime_new_yyyyMMdd, goodsIdList);
                        }else if(Tools.getInteger(pyqAutoConfig.getRandomImg()).intValue() == 1){ //启用随机商品
                            //分页查询
                            Page<PyqHdkGoods> page = new Page<>();
                            page.setCurrent(1);
                            page.setSize(10);
                            PyqHdkGoodsQuery pyqHdkGoodsQuery = new PyqHdkGoodsQuery();
                            pyqHdkGoodsQuery.setAddDay(sendTime_new_yyyyMMdd);
                            pyqHdkGoodsQuery.setGoodsIdExcludeList(goodsIdList);
                            List<PyqHdkGoods> pyqHdkGoodsList = pyqHdkGoodsMapper.findByList(page,  pyqHdkGoodsQuery);
                            if(pyqHdkGoodsList != null && pyqHdkGoodsList.size() > 0){
                                //获取此数组内的随机对象
                                int random = RandomUtil.getRandomInt(0, pyqHdkGoodsList.size()-1);
                                pyqHdkGoods = pyqHdkGoodsList.get(random);
                            }
                        }
                        if(pyqHdkGoods != null){
                            //发送明细
                            PyqJobDetail pyqJobDetail = sendPyqJobDetailByHdkGoodsSync(pyqAutoConfig, deviceUniqueId, pyqJobId, pyqHdkGoods, now);
                            if(pyqJobDetail != null){
                                if(pyqJobDetail.getStatus() != null && pyqJobDetail.getStatus().intValue() == PyqJobDetailStatusEnum.NOSEND.getValue()){
                                    totalCount ++ ;
                                }
                                pyqJobDetail_job = pyqJobDetail;
                            }
                        }

                    }catch (Exception e){
                        logger.error("单个机器人自动发送朋友圈失败；error={}", e);
                    }
                }
            }else if(type.intValue() == 2 || type.intValue() == 3){//悠哉精品淘宝商品和悠哉精品拼多多商品

                //获取悠哉精品库基础曝光量
                int baseExposureNum = 0;
                UzaiRespVo<Integer> uzaiRespVo_baseExposureNum = uzaiBusinessFeignService.selectBaseExposureNum();
                logger.info("--调用查询悠哉精品库基础曝光量--result={}",JSONObject.toJSONString(uzaiRespVo_baseExposureNum));
                if(uzaiRespVo_baseExposureNum.getCode() == 200 && uzaiRespVo_baseExposureNum.getData() != null){
                    baseExposureNum = uzaiRespVo_baseExposureNum.getData();
                }

                //新的发送时间
                Integer sendTime_new = pyqAutoConfig.getSendTime();
                //新的发送时间天格式
                String sendTime_new_yyyyMMdd = Tools.getDateFormat(new Date(sendTime_new.intValue() * 1000L), "yyyy-MM-dd");

                for(Long deviceUniqueId : deviceUniqueIdList){
                    try {
                        //封装已经发送的商品列表
                        List<Long> goodsIdList = new ArrayList<>();
                        //获取每个机器人的已经发送的商品信息
                        //List<PyqAutoSend> pyqAutoSendList = pyqAutoSendMapper.selectByDeviceUniqueIdAndType(deviceUniqueId, type);
                        Integer limitRepeatDay = pyqAutoConfig.getLimitRepeatDay();
                        if(limitRepeatDay == null){
                            limitRepeatDay = 3; //默认为3天
                        }
                        Integer sendTime = Tools.getInteger(pyqAutoConfig.getSendTime()); //查询任务的最新发送时间
                        //不重复发送时间=最新时间-不重复发送限制时间
                        Integer limitRepeatTime =  sendTime - limitRepeatDay * 24 * 3600;
                        List<PyqAutoSend> pyqAutoSendList = pyqAutoSendMapper.selectByDeviceUniqueIdAndAutoConfigIdAndSendTime(deviceUniqueId, pyqAutoConfig.getId(), limitRepeatTime);
                        if(pyqAutoSendList != null){
                            for (PyqAutoSend pyqAutoSend : pyqAutoSendList){
                                goodsIdList.add(pyqAutoSend.getGoodsid());
                            }
                        }

                        //查询悠哉精品库商品
                        PyqLlyGoodsVo pyqLlyGoodsVo = getUzjpkGoods(pyqAutoConfig, deviceUniqueId, sendTime_new, goodsIdList, baseExposureNum);

                        //找到商品,则发送朋友圈明细
                        if(pyqLlyGoodsVo != null){
                            //发送明细
                            PyqJobDetail pyqJobDetail = sendPyqJobDetailByYzjpGoodsSync(pyqAutoConfig, deviceUniqueId, pyqJobId, pyqLlyGoodsVo, now, pyqDevicePlan.getDomain());
                            if(pyqJobDetail != null){//生成朋友圈明细成功
                                totalCount ++ ;
                                pyqJobDetail_job = pyqJobDetail;
                                //如果商品未参加推广，则下线该商品
                                if("未参加商品推广".equals(pyqJobDetail.getFailMsg()) || "商品信息有误".equals(pyqJobDetail.getFailMsg())){
//                                    StopGoodsDto stopGoodsDto = new StopGoodsDto();
//                                    stopGoodsDto.setId(pyqLlyGoodsVo.getId());
//                                    UzaiRespVo<Object> uzaiRespVo = uzaiBusinessFeignService.stopGoods(stopGoodsDto);
//                                    logger.info("--远程下线悠哉精品库商品---para={},result={}",JSONObject.toJSONString(stopGoodsDto), JSONObject.toJSONString(uzaiRespVo));
//                                    if(uzaiRespVo != null && uzaiRespVo.getCode() == 200) {
                                        //通知客服钉钉群报警
                                        DindDingGroupMsgEnum dindDingGroupMsgEnum = DindDingGroupMsgEnum.GOODS_ERROR;
                                        if (dindDingGroupMsgEnum != null) {
                                            SysRunlogWarningDto sysRunlogWarningDto_stopGoods = new SysRunlogWarningDto();
                                            String text = String.format(dindDingGroupMsgEnum.getMsg(), pyqLlyGoodsVo.getGoodsTailId());
                                            text = text + "\n" +"机器人id：" + deviceUniqueId;
                                            sysRunlogWarningDto_stopGoods.setText(text);
                                            sysRunlogWarningDto_stopGoods.setSecret(dindDingGroupMsgEnum.getSecret());
                                            sysRunlogWarningDto_stopGoods.setWebhook(dindDingGroupMsgEnum.getWebhook());
                                            sysRunlogWarningDto_stopGoods.setOpenConversationId(dindDingGroupMsgEnum.getOpenConversationId());
                                            UzaiRespVo<Object> objectUzaiRespVo_stopGoods = uzaiManageFeignService.sysRunlogWarning(sysRunlogWarningDto_stopGoods);
                                            logger.info("--通知客服钉钉群报警商品下线接口---para={},result={}", JSONObject.toJSONString(sysRunlogWarningDto_stopGoods), JSONObject.toJSONString(objectUzaiRespVo_stopGoods));
                                        }

                                        //再次查询一次商品进行转链
//                                        goodsIdList.add(pyqLlyGoodsVo.getId()); //将上次转链失败的商品排除掉
//                                        PyqLlyGoodsVo pyqLlyGoodsVo_again = getUzjpkGoods(pyqAutoConfig, deviceUniqueId, sendTime_new, goodsIdList, baseExposureNum);
//                                        //找到商品,则发送朋友圈明细
//                                        if (pyqLlyGoodsVo_again != null) {
//                                            //发送官方库明细
//                                            PyqJobDetail pyqJobDetail_again = sendPyqJobDetailByYzjpGoodsSync(pyqAutoConfig, deviceUniqueId, pyqJobId, pyqLlyGoodsVo_again, now, pyqDevicePlan.getDomain());
//                                            if (pyqJobDetail_again != null) {//转链成功
//                                                if(pyqJobDetail.getStatus() != null && pyqJobDetail.getStatus().intValue() == PyqJobDetailStatusEnum.NOSEND.getValue()){
//                                                    totalCount ++ ;
//                                                }
//                                                pyqJobDetail_job = pyqJobDetail_again;
//                                                //如果商品未参加推广，则下线该商品
//                                                if ("未参加商品推广".equals(pyqJobDetail_again.getFailMsg()) || "商品信息有误".equals(pyqJobDetail.getFailMsg())) {
////                                                    StopGoodsDto stopGoodsDto_again = new StopGoodsDto();
////                                                    stopGoodsDto_again.setId(pyqLlyGoodsVo_again.getId());
////                                                    UzaiRespVo<Object> uzaiRespVo_again = uzaiBusinessFeignService.stopGoods(stopGoodsDto_again);
////                                                    logger.info("--远程下线悠哉精品库商品---para={},result={}", JSONObject.toJSONString(stopGoodsDto_again), JSONObject.toJSONString(uzaiRespVo_again));
////                                                    if (uzaiRespVo_again != null && uzaiRespVo_again.getCode() == 200) {
//                                                        //通知客服钉钉群报警
//                                                        DindDingGroupMsgEnum dindDingGroupMsgEnum_again = DindDingGroupMsgEnum.GOODS_ERROR;
//                                                        if (dindDingGroupMsgEnum_again != null) {
//                                                            SysRunlogWarningDto sysRunlogWarningDto_stopGoods_again = new SysRunlogWarningDto();
//                                                            String text = String.format(dindDingGroupMsgEnum_again.getMsg(), pyqLlyGoodsVo_again.getGoodsTailId());
//                                                            text = text + "\n" +"机器人id：" + deviceUniqueId;
//                                                            sysRunlogWarningDto_stopGoods_again.setText(text);
//                                                            sysRunlogWarningDto_stopGoods_again.setSecret(dindDingGroupMsgEnum_again.getSecret());
//                                                            sysRunlogWarningDto_stopGoods_again.setWebhook(dindDingGroupMsgEnum_again.getWebhook());
//                                                            UzaiRespVo<Object> objectUzaiRespVo_stopGoods = uzaiManageFeignService.sysRunlogWarning(sysRunlogWarningDto_stopGoods_again);
//                                                            logger.info("--通知客服钉钉群报警商品下线接口---para={},result={}", JSONObject.toJSONString(sysRunlogWarningDto_stopGoods_again), JSONObject.toJSONString(objectUzaiRespVo_stopGoods));
//                                                        }
////                                                    }
//                                                }
//                                            }
//                                        } else {//未找到商品，提示钉钉报警
//                                            //限流判断，5分钟之内只发送一次
//                                            String rateLimitKey = "autoSendPyq-noGoods-merid=" + pyqAutoConfig.getMerId();
//                                            boolean inRateLimit = ratelimitService.inRateLimit(rateLimitKey, 1, 300);
//                                            if (inRateLimit) {//符合条件，才发送
//                                                Merchant merchant = merchantService.findByMerId(pyqAutoConfig.getMerId());
//                                                if (merchant != null) {
//                                                    //通知商品不够发送朋友圈报警
//                                                    DindDingGroupMsgEnum dindDingGroupMsgEnum_not_enough = DindDingGroupMsgEnum.GOODS_NOT_ENOUGH;
//                                                    if (dindDingGroupMsgEnum_not_enough != null) {
//                                                        SysRunlogWarningDto sysRunlogWarningDto_not_enough = new SysRunlogWarningDto();
//                                                        String text = String.format(dindDingGroupMsgEnum_not_enough.getMsg(), merchant.getMobile());
//                                                        if(Tools.getInteger(pyqAutoConfig.getType()).intValue() == 2){ //淘宝商品
//                                                            text = text + "\n商品平台:" + "淘宝";
//                                                        }else if(Tools.getInteger(pyqAutoConfig.getType()).intValue() == 3){//拼多多商品
//                                                            text = text + "\n商品平台:" + "拼多多";
//                                                        }
//                                                        sysRunlogWarningDto_not_enough.setText(text);
//                                                        sysRunlogWarningDto_not_enough.setSecret(dindDingGroupMsgEnum_not_enough.getSecret());
//                                                        sysRunlogWarningDto_not_enough.setWebhook(dindDingGroupMsgEnum_not_enough.getWebhook());
//                                                        UzaiRespVo<Object> objectUzaiRespVo_not_enough = uzaiManageFeignService.sysRunlogWarning(sysRunlogWarningDto_not_enough);
//                                                        logger.info("--调用精品库商品不够发送朋友圈消息接口-deviceUniqueId={},para={},result={}", deviceUniqueId, JSONObject.toJSONString(sysRunlogWarningDto_not_enough), JSONObject.toJSONString(objectUzaiRespVo_not_enough));
//                                                    }
//                                                }
//                                            }
//                                        }
//                                  }
                                }
                            }
                        }else{//未找到商品，提示钉钉报警
                            //未找到商品，添加空的发送明细
                            PyqJobDetail pyqJobDetail = createPyqDetailByNoGoods(pyqAutoConfig, deviceUniqueId, pyqJobId, 0, now);
                            if(pyqJobDetail != null){
                                totalCount ++ ;
                                pyqJobDetail_job = pyqJobDetail;
                            }

                            //限流判断，5分钟之内只发送一次
//                            String rateLimitKey = "autoSendPyq-noGoods-merid=" + pyqAutoConfig.getMerId();
//                            boolean inRateLimit = ratelimitService.inRateLimit(rateLimitKey,1,300);
//                            if (inRateLimit){//符合条件，才发送
//                                Merchant merchant = merchantService.findByMerId(pyqAutoConfig.getMerId());
//                                if(merchant != null){
//                                    //通知商品不够发送朋友圈报警
//                                    DindDingGroupMsgEnum dindDingGroupMsgEnum_not_enough = DindDingGroupMsgEnum.GOODS_NOT_ENOUGH;
//                                    if(dindDingGroupMsgEnum_not_enough != null){
//                                        SysRunlogWarningDto sysRunlogWarningDto_not_enough = new SysRunlogWarningDto();
//                                        String text = String.format(dindDingGroupMsgEnum_not_enough.getMsg(), merchant.getMobile());
//                                        if(Tools.getInteger(pyqAutoConfig.getType()).intValue() == 2){ //淘宝商品
//                                            text = text + "\n商品平台:" + "淘宝";
//                                        }else if(Tools.getInteger(pyqAutoConfig.getType()).intValue() == 3){//拼多多商品
//                                            text = text + "\n商品平台:" + "拼多多";
//                                        }
//                                        sysRunlogWarningDto_not_enough.setText(text);
//                                        sysRunlogWarningDto_not_enough.setSecret(dindDingGroupMsgEnum_not_enough.getSecret());
//                                        sysRunlogWarningDto_not_enough.setWebhook(dindDingGroupMsgEnum_not_enough.getWebhook());
//                                        UzaiRespVo<Object> objectUzaiRespVo_not_enough = uzaiManageFeignService.sysRunlogWarning(sysRunlogWarningDto_not_enough);
//                                        logger.info("--调用精品库商品不够发送朋友圈消息接口---deviceUniqueId={},para={},result={}", deviceUniqueId,JSONObject.toJSONString(sysRunlogWarningDto_not_enough), JSONObject.toJSONString(objectUzaiRespVo_not_enough));
//                                    }
//                                }
//                            }
                        }
                    }catch (Exception e){
                        logger.error("单个机器人自动发送朋友圈失败；error={}", e);
                    }
                }
            }else if(type.intValue() == 10  && pyqAutoConfig.getYzjxGoodsUserId() != null){//悠哉精品优友圈任务

                //验证悠友圈会员存不存在
                PyqLlyGoodsUserIdDto pyqLlyGoodsUserIdDto = new PyqLlyGoodsUserIdDto();
                pyqLlyGoodsUserIdDto.setUserId(pyqAutoConfig.getYzjxGoodsUserId());
                pyqLlyGoodsUserIdDto.setMerId(pyqAutoConfig.getMerId());
                UzaiRespVo<PyqLlyGoodsUserVo> uzaiRespVo_goodsUser =  uzaiBusinessFeignService.goodsUserSelectById(pyqLlyGoodsUserIdDto);
                logger.info("---调用推老板悠哉精品库悠友圈详情查询--para={},result={}", JSONObject.toJSONString(pyqLlyGoodsUserIdDto), JSONObject.toJSONString(uzaiRespVo_goodsUser));
                if(uzaiRespVo_goodsUser.getCode() != 200 || uzaiRespVo_goodsUser.getData() == null){
                    logger.error(JSONObject.toJSONString(new BizLog(LogBizTypeEnum.CONSOLE_PYQ_SEND_AUTO_VALUE,
                            pyqAutoConfig.getMerId(), 0, null,
                            "",0L,
                            "该自动发送任务配置的悠友圈不存在：uerid=" + pyqAutoConfig.getYzjxGoodsUserId())));
                    return;
                }

                //新的发送时间
                Integer sendTime_new = pyqAutoConfig.getSendTime();
                //新的发送时间天格式
                String sendTime_new_yyyyMMdd = Tools.getDateFormat(new Date(sendTime_new.intValue() * 1000L), "yyyy-MM-dd");

                for(Long deviceUniqueId : deviceUniqueIdList){
                    try {
                        //封装已经发送过的商品最大的主键id
                        Long goodsIdMax = 0L;
                        //获取每个机器人的已经发送的最大主键id的商品信息
                        PyqAutoSend pyqAutoSend = pyqAutoSendMapper.selectByMaxGoodsId(deviceUniqueId, type);
                        if(pyqAutoSend != null){
                            goodsIdMax = pyqAutoSend.getGoodsid();
                        }

                        //查询悠哉精品库商品
                        PyqLlyGoodsVo pyqLlyGoodsVo = getUzjpkGoodsByGoodsUser(pyqAutoConfig, deviceUniqueId, sendTime_new, goodsIdMax, pyqAutoConfig.getYzjxGoodsUserId());

                        //找到商品,则发送朋友圈明细
                        if(pyqLlyGoodsVo != null){
                            //发送明细
                            PyqJobDetail pyqJobDetail = sendPyqJobDetailByYzjpGoodsSync(pyqAutoConfig, deviceUniqueId, pyqJobId, pyqLlyGoodsVo, now, pyqDevicePlan.getDomain());
                            if(pyqJobDetail != null){//生成朋友圈明细成功
                                totalCount ++ ;
                                pyqJobDetail_job = pyqJobDetail;

                                //如果商品未参加推广，则下线该商品
                                if("未参加商品推广".equals(pyqJobDetail.getFailMsg()) || "商品信息有误".equals(pyqJobDetail.getFailMsg())){
//                                    StopGoodsDto stopGoodsDto = new StopGoodsDto();
//                                    stopGoodsDto.setId(pyqLlyGoodsVo.getId());
//                                    UzaiRespVo<Object> uzaiRespVo = uzaiBusinessFeignService.stopGoods(stopGoodsDto);
//                                    logger.info("--远程下线悠哉精品库商品---para={},result={}",JSONObject.toJSONString(stopGoodsDto), JSONObject.toJSONString(uzaiRespVo));
//                                    if(uzaiRespVo != null && uzaiRespVo.getCode() == 200) {
                                        //通知客服钉钉群报警
                                        DindDingGroupMsgEnum dindDingGroupMsgEnum = DindDingGroupMsgEnum.GOODS_ERROR;
                                        if (dindDingGroupMsgEnum != null) {
                                            SysRunlogWarningDto sysRunlogWarningDto_stopGoods = new SysRunlogWarningDto();
                                            String text = String.format(dindDingGroupMsgEnum.getMsg(), pyqLlyGoodsVo.getGoodsTailId());
                                            sysRunlogWarningDto_stopGoods.setText(text);
                                            text = text + "\n" +"机器人id：" + deviceUniqueId;
                                            sysRunlogWarningDto_stopGoods.setSecret(dindDingGroupMsgEnum.getSecret());
                                            sysRunlogWarningDto_stopGoods.setWebhook(dindDingGroupMsgEnum.getWebhook());
                                            sysRunlogWarningDto_stopGoods.setOpenConversationId(dindDingGroupMsgEnum.getOpenConversationId());
                                            UzaiRespVo<Object> objectUzaiRespVo_stopGoods = uzaiManageFeignService.sysRunlogWarning(sysRunlogWarningDto_stopGoods);
                                            logger.info("--通知客服钉钉群报警商品下线接口---para={},result={}", JSONObject.toJSONString(sysRunlogWarningDto_stopGoods), JSONObject.toJSONString(objectUzaiRespVo_stopGoods));
                                        }

//                                        //再次查询一次商品进行转链
//                                        //如果最大商品id小于上次查询到的商品id，则最大商品id为上次查询到的商品id(排除上次的商品id)
//                                        if(goodsIdMax < pyqLlyGoodsVo.getId()){
//                                            goodsIdMax = pyqLlyGoodsVo.getId();
//                                        }
//                                        PyqLlyGoodsVo pyqLlyGoodsVo_again = getUzjpkGoodsByGoodsUser(pyqAutoConfig, deviceUniqueId, sendTime_new, goodsIdMax, pyqAutoConfig.getYzjxGoodsUserId());
//                                        //找到商品,则发送朋友圈明细
//                                        if (pyqLlyGoodsVo_again != null) {
//                                            //发送官方库明细
//                                            PyqJobDetail pyqJobDetail_again = sendPyqJobDetailByYzjpGoodsSync(pyqAutoConfig, deviceUniqueId, pyqJobId, pyqLlyGoodsVo_again, now, pyqDevicePlan.getDomain());
//                                            if (pyqJobDetail_again != null) {//转链成功
//                                                if(pyqJobDetail.getStatus() != null && pyqJobDetail.getStatus().intValue() == PyqJobDetailStatusEnum.NOSEND.getValue()){
//                                                    totalCount ++ ;
//                                                }
//                                                pyqJobDetail_job = pyqJobDetail_again;
//                                                //如果商品未参加推广，则下线该商品
//                                                if ("未参加商品推广".equals(pyqJobDetail_again.getFailMsg()) || "商品信息有误".equals(pyqJobDetail.getFailMsg())) {
////                                                    StopGoodsDto stopGoodsDto_again = new StopGoodsDto();
////                                                    stopGoodsDto_again.setId(pyqLlyGoodsVo_again.getId());
////                                                    UzaiRespVo<Object> uzaiRespVo_again = uzaiBusinessFeignService.stopGoods(stopGoodsDto_again);
////                                                    logger.info("--远程下线悠哉精品库商品---para={},result={}", JSONObject.toJSONString(stopGoodsDto_again), JSONObject.toJSONString(uzaiRespVo_again));
////                                                    if (uzaiRespVo_again != null && uzaiRespVo_again.getCode() == 200) {
//                                                        //通知客服钉钉群报警
//                                                        DindDingGroupMsgEnum dindDingGroupMsgEnum_again = DindDingGroupMsgEnum.GOODS_ERROR;
//                                                        if (dindDingGroupMsgEnum_again != null) {
//                                                            SysRunlogWarningDto sysRunlogWarningDto_stopGoods_again = new SysRunlogWarningDto();
//                                                            String text = String.format(dindDingGroupMsgEnum_again.getMsg(), pyqLlyGoodsVo_again.getGoodsTailId());
//                                                            text = text + "\n" +"机器人id：" + deviceUniqueId;
//                                                            sysRunlogWarningDto_stopGoods_again.setText(text);
//                                                            sysRunlogWarningDto_stopGoods_again.setSecret(dindDingGroupMsgEnum_again.getSecret());
//                                                            sysRunlogWarningDto_stopGoods_again.setWebhook(dindDingGroupMsgEnum_again.getWebhook());
//                                                            UzaiRespVo<Object> objectUzaiRespVo_stopGoods = uzaiManageFeignService.sysRunlogWarning(sysRunlogWarningDto_stopGoods_again);
//                                                            logger.info("--通知客服钉钉群报警商品下线接口---para={},result={}", JSONObject.toJSONString(sysRunlogWarningDto_stopGoods_again), JSONObject.toJSONString(objectUzaiRespVo_stopGoods));
//                                                        }
////                                                    }
//                                                }
//                                            }
//                                        } else {//未找到商品，提示钉钉报警
//                                            //限流判断，5分钟之内只发送一次
//                                            String rateLimitKey = "autoSendPyq-noGoods-merid=" + pyqAutoConfig.getMerId();
//                                            boolean inRateLimit = ratelimitService.inRateLimit(rateLimitKey, 1, 300);
//                                            if (inRateLimit) {//符合条件，才发送
//                                                Merchant merchant = merchantService.findByMerId(pyqAutoConfig.getMerId());
//                                                if (merchant != null) {
//                                                    //通知商品不够发送朋友圈报警
//                                                    DindDingGroupMsgEnum dindDingGroupMsgEnum_not_enough = DindDingGroupMsgEnum.GOODS_NOT_ENOUGH;
//                                                    if (dindDingGroupMsgEnum_not_enough != null) {
//                                                        SysRunlogWarningDto sysRunlogWarningDto_not_enough = new SysRunlogWarningDto();
//                                                        String text = String.format(dindDingGroupMsgEnum_not_enough.getMsg(), merchant.getMobile());
//                                                        sysRunlogWarningDto_not_enough.setText(text);
//                                                        sysRunlogWarningDto_not_enough.setSecret(dindDingGroupMsgEnum_not_enough.getSecret());
//                                                        sysRunlogWarningDto_not_enough.setWebhook(dindDingGroupMsgEnum_not_enough.getWebhook());
//                                                        //UzaiRespVo<Object> objectUzaiRespVo_not_enough = uzaiManageFeignService.sysRunlogWarning(sysRunlogWarningDto_not_enough);
//                                                        //logger.info("--调用精品库商品不够发送悠友圈消息接口---para={},result={}", JSONObject.toJSONString(sysRunlogWarningDto_not_enough), JSONObject.toJSONString(objectUzaiRespVo_not_enough));
//                                                    }
//                                                }
//                                            }
//                                        }
//                                  }
                                }
                            }
                        }else{//未找到商品，提示钉钉报警

                            //未找到商品，添加空的发送明细
                            PyqJobDetail pyqJobDetail = createPyqDetailByNoGoods(pyqAutoConfig, deviceUniqueId, pyqJobId, 0, now);
                            if(pyqJobDetail != null){
                                totalCount ++ ;
                                pyqJobDetail_job = pyqJobDetail;
                            }

                            //限流判断，5分钟之内只发送一次
//                            String rateLimitKey = "autoSendPyq-noGoods-merid=" + pyqAutoConfig.getMerId();
//                            boolean inRateLimit = ratelimitService.inRateLimit(rateLimitKey,1,300);
//                            if (inRateLimit){//符合条件，才发送
//                                Merchant merchant = merchantService.findByMerId(pyqAutoConfig.getMerId());
//                                if(merchant != null){
//                                    //通知商品不够发送朋友圈报警
//                                    DindDingGroupMsgEnum dindDingGroupMsgEnum_not_enough = DindDingGroupMsgEnum.GOODS_NOT_ENOUGH;
//                                    if(dindDingGroupMsgEnum_not_enough != null){
//                                        SysRunlogWarningDto sysRunlogWarningDto_not_enough = new SysRunlogWarningDto();
//                                        String text = String.format(dindDingGroupMsgEnum_not_enough.getMsg(), merchant.getMobile());
//                                        sysRunlogWarningDto_not_enough.setText(text);
//                                        sysRunlogWarningDto_not_enough.setSecret(dindDingGroupMsgEnum_not_enough.getSecret());
//                                        sysRunlogWarningDto_not_enough.setWebhook(dindDingGroupMsgEnum_not_enough.getWebhook());
//                                        //UzaiRespVo<Object> objectUzaiRespVo_not_enough = uzaiManageFeignService.sysRunlogWarning(sysRunlogWarningDto_not_enough);
//                                        //logger.info("--调用精品库商品不够发送悠友圈消息接口---para={},result={}",JSONObject.toJSONString(sysRunlogWarningDto_not_enough), JSONObject.toJSONString(objectUzaiRespVo_not_enough));
//                                    }
//                                }
//                            }
                        }
                    }catch (Exception e){
                        logger.error("单个机器人自动发送朋友圈失败；error={}", e);
                    }
                }
            }else if(type.intValue() == 1){ //图文
                for(Long deviceUniqueId : deviceUniqueIdList){
                    //获取每个机器人的将要发送的商品信息
                    PyqHdkGoods pyqHdkGoods = new PyqHdkGoods();
                    //发送明细
                    PyqJobDetail pyqJobDetail = sendPyqJobDetailByCustomSync(pyqAutoConfig, deviceUniqueId, pyqJobId, now);
                    if(pyqJobDetail != null){
                        if(pyqJobDetail.getStatus() != null && pyqJobDetail.getStatus().intValue() == PyqJobDetailStatusEnum.NOSEND.getValue()){
                            totalCount ++ ;
                        }
                        pyqJobDetail_job = pyqJobDetail;
                    }
                }
            }

            //大于0，才有主表
            if(totalCount > 0){
                PyqJob pyqJob = new PyqJob();
                pyqJob.setId(pyqJobId);
                pyqJob.setMerId(pyqAutoConfig.getMerId());
                pyqJob.setDeviceType(DeviceTypeEnum.DT_PC_WECHAT.getKey());
                pyqJob.setStatus(PyqJobStatusEnum.NOSTART.getValue());
                pyqJob.setType(pyqAutoConfig.getType());
                pyqJob.setSource(1); //自动发圈
                pyqJob.setPlatform(pyqJobDetail_job.getPlatform());
                pyqJob.setDevicePlanId(pyqAutoConfig.getDevicePlanId());
                pyqJob.setCreateTime(now);
                pyqJob.setUpdateTime(now);
                pyqJob.setSendTime(pyqAutoConfig.getSendTime());
                pyqJob.setImgs(pyqJobDetail_job.getImgs());
                pyqJob.setContentId(pyqAutoConfig.getContentId());
                pyqJob.setContent(pyqJobDetail_job.getContent());
                pyqJob.setCommentId(pyqAutoConfig.getCommentId());
                pyqJob.setCommentContent(pyqJobDetail_job.getCommentContent());
                pyqJob.setCouponId(pyqJobDetail_job.getCouponId());
                pyqJob.setCouponVal(pyqJobDetail_job.getCouponVal());
                pyqJob.setFinalPrice(pyqJobDetail_job.getFinalPrice());
                pyqJob.setTotalCount(totalCount);
                pyqJob.setItemId(pyqJobDetail_job.getItemId());
                pyqJob.setItemTailId(pyqJobDetail_job.getItemTailId());
                pyqJob.setItemHeaderId(pyqJobDetail_job.getItemHeaderId());
                //2023-08-23 修改增加媒体信息
                pyqJob.setImgs(null); //新协议imgs已放弃
                pyqJob.setFeedMedia(pyqJobDetail_job.getFeedMediaList());
                pyqJob.setAttachType(pyqJobDetail_job.getAttachType());
                pyqJob.setVideoNumber(pyqJobDetail_job.getPyqVideoNumber());

                //添加发送任务
                int i = pyqJobMapper.insert(pyqJob);

                //添加成功才保持
                if(i == 1){
                    //修改最新的发送时间(放到发送完成之后才保存)
                    pyqAutoConfigMapper.updateSendTimeById(pyqAutoConfig);
                }

            }
        }
    }

    /**
     * 自动发送朋友圈评论
     * @author lucher
     * @date 2022/9/19 14:05
     * @param pyqFollowComment
     */
    public void autoSendPyqComment(PyqFollowComment pyqFollowComment){

        if(pyqFollowComment.getDeviceUniqueId() == null ){
            return;
        }

        if(StringUtils.isBlank(pyqFollowComment.getFollowedSnsId())){
            return;
        }

        if(StringUtils.isBlank(pyqFollowComment.getContent())){
            return;
        }

        Device device = deviceService.findDeviceInfoByDeviceUniqueId(pyqFollowComment.getDeviceUniqueId(), null,pyqFollowComment.getMerId());
        if(device == null){
            return;
        }

        String uzai_pyq_job_detail = merchantService.getMechantOtherEsIndexName(EsIndexName.UZAI_PYQ_JOB_DETAIL, pyqFollowComment.getMerId());

        //查询该朋友圈明细所在的朋友圈是否存在
        PyqFollowContent pyqFollowContent = pyqFollowContentMapper.selectByDeviceUniqueIdAndFollowedSnsId(pyqFollowComment.getDeviceUniqueId(), pyqFollowComment.getFollowedSnsId());
        if(pyqFollowContent != null){ //存在，则需要查询朋友圈是否发送成功
            Map<String,Object> pyqJobDetailEsMap = elasticsearchUtilGroupMsg.searchDataById(uzai_pyq_job_detail, pyqFollowContent.getPyqId(), null);
            PyqJobDetail pyqJobDetail = JSONObject.parseObject(Tools.getStrEmpty(JSONObject.toJSONString(pyqJobDetailEsMap)), PyqJobDetail.class);
            //pydId不为空，则表示已经发送成功
            if(pyqJobDetail != null){
                //朋友圈唯一id
                String snsId = pyqJobDetail.getPyqId();
                if(StringUtils.isNotBlank(snsId)){
                    //发送发送评论微服务
                    MsgDto<PostSnsCommentDto> msgDto = new MsgDto<>();
                    PostSnsCommentDto  postSnsCommentDto = new PostSnsCommentDto();
                    msgDto.setContent(postSnsCommentDto);
                    msgDto.setId(IdWorker.getId());
                    msgDto.setDeviceType(device.getRecvmsgType());
                    msgDto.setDeviceUniqueId(device.getId());
                    msgDto.setMerId(pyqFollowComment.getMerId());
                    msgDto.setMsgType(MessageFuncEnum.POST_COMMENT_TASK.getValue());
                    //朋友圈评论
                    List<String> commentList = new ArrayList<>();
                    commentList.add(pyqFollowComment.getContent());
                    postSnsCommentDto.setId(IdWorker.getId()); //随机ID
                    postSnsCommentDto.setContent(commentList);
                    postSnsCommentDto.setSnsid(snsId);
                    postSnsCommentDto.setPostid(pyqJobDetail.getPostId());
                    noticeMsgPushProducerService.sendPyqComment(msgDto);

                    //修改数据库评论信息
                    pyqFollowComment.setPyqId(pyqFollowContent.getPyqId());//修改朋友圈主键id
                    pyqFollowComment.setStatus(1); //已发送
                    pyqFollowCommentMapper.updateByIdSelective(pyqFollowComment);

                    //修改朋友圈明细
                    JSONObject jsonObject = new JSONObject();
                    List<String> commentList_new = new ArrayList<>();
                    String commentContent = pyqJobDetail.getCommentContent();
                    if(StringUtils.isNotBlank(commentContent)){
                        try {
                            commentList_new = JSONObject.parseArray(commentContent, String.class);
                        }catch (Exception e){

                        }
                    }
                    //修改旧朋友圈评论内容-新增加评论
                    commentList_new.add(pyqFollowComment.getContent());
                    jsonObject.put("commentContent", JSONObject.toJSONString(commentList_new)); //删除朋友圈
                    jsonObject.put("updateTime", DateUtil.getNowTime());
                    elasticsearchUtilGroupMsg.updateDataById(jsonObject, uzai_pyq_job_detail, pyqJobDetail.getId());
                }
            }
        }
    }


    /**
     * 自动发送官方商品朋友圈商品明细
     * @author liuqi
     * @date 2021/8/25 11:38
     * @param pyqAutoConfig
     * @return null
     */
    private PyqJobDetail sendPyqJobDetailByGfkGoodsSync(PyqAutoConfig pyqAutoConfig, Long deviceUniqueId, Long pyqJobId, PyqGfkGoods pyqgfkGoods, int now){
        Device device = deviceService.findDeviceInfoByDeviceUniqueId(deviceUniqueId, null,pyqAutoConfig.getMerId());
        if(device == null){
            return null;
        }

        //赋值子任务明细
        PyqJobDetail pyqJobDetail = new PyqJobDetail() ;
        pyqJobDetail.setId(String.valueOf(IdWorker.getId()));
        pyqJobDetail.setVersion(0L);
        pyqJobDetail.setMerId(pyqAutoConfig.getMerId());
        pyqJobDetail.setJobId(pyqJobId);
        pyqJobDetail.setDeviceUniqueId(deviceUniqueId);
        pyqJobDetail.setDeviceType(device.getRecvmsgType());
        pyqJobDetail.setType(pyqAutoConfig.getType());
        pyqJobDetail.setPlatform(0);//淘宝
        pyqJobDetail.setSource(1); //发送来源（0手动发送；1自动发圈；2自动跟发）
        pyqJobDetail.setStartTime(pyqAutoConfig.getSendTime());
        pyqJobDetail.setSendTime(pyqAutoConfig.getSendTime());
        pyqJobDetail.setItemId(pyqgfkGoods.getItemid());
        pyqJobDetail.setCouponId(pyqgfkGoods.getCouponid());
        pyqJobDetail.setCouponVal(pyqgfkGoods.getCouponmoney());
        pyqJobDetail.setFinalPrice(pyqgfkGoods.getItemendprice());
        //图片
        List<String> imgList = new ArrayList<>();
        //添加商品图片
        String itempic = Tools.getStr(pyqgfkGoods.getItempic());
        if(StringUtils.isNotBlank(itempic)){
            try {
                List<String> itempicList = JSONArray.parseArray(itempic, String.class);
                if(itempicList != null && itempicList.size() > 0){
                    for (String item : itempicList){
                        if(StringUtils.isNotBlank(item)){
                            imgList.add(item);
                        }
                    }
                }
            }catch (Exception e){

            }
        }

        //朋友圈自定义图片只有一张
        if(StringUtils.isNotBlank(pyqAutoConfig.getImgs())){
            try {
                if(imgList.size() > 8){
                    imgList = imgList.subList(0, 8);
                }
                imgList.addAll(JSONObject.parseArray(pyqAutoConfig.getImgs(), String.class));
            }catch (Exception e){

            }
        }

        if(imgList.size() > 9){
            imgList = imgList.subList(0, 9);
        }

        pyqJobDetail.setImgs(Tools.getStrEmpty(JSONObject.toJSONString(imgList)));
        //2023-08-08 修改增加媒体信息
        if(imgList != null && imgList.size() > 0){
            List<FeedMedia> feedMediaList = new ArrayList<>();
            for (String img : imgList) {
                FeedMedia feedMedia = new FeedMedia();
                feedMedia.setUrl(img);
                feedMediaList.add(feedMedia);
            }
            pyqJobDetail.setFeedMediaList(Tools.getStrEmpty(JSONObject.toJSONString(feedMediaList)));
        }

        pyqJobDetail.setCreateTime(now);
        pyqJobDetail.setUpdateTime(now);

        //朋友圈内容
        //朋友圈内容替换变量
        String content = Tools.getStr(pyqAutoConfig.getContent());
        //券后价
        Double itemendprice = Tools.getDouble(pyqgfkGoods.getItemendprice());
        //优惠券金额
        Double couponmoney = Tools.getDouble(pyqgfkGoods.getCouponmoney());
        //原价 itemprice
        Double itemprice = Tools.getDouble(pyqgfkGoods.getItemprice());
        content = content.replace("[商品标题]",Tools.getStr(pyqgfkGoods.getItemtitle()))
                .replace("[文案]",Tools.getStr(pyqgfkGoods.getCopyContent()))
                .replace("[原价]",  String.valueOf(itemprice.doubleValue()))
                .replace("[券后价]", String.valueOf(itemendprice.doubleValue()));
        //替换随机字符串
        content = MsgSplitUtil.replaceRandomStrArgs(content);
        //替换随机表情
        while (content.contains("[随机表情]")){
            content = content.replaceFirst("\\[随机表情\\]", Tools.getStr(EmojiUtil.getRandomEmoji()));
        }

        pyqJobDetail.setContent(content);

        //评论内容替换变量
        List<String> commentList = new ArrayList<>();

        //是否发送商品自带评论 1-开启
        if(Tools.getInteger(pyqAutoConfig.getGoodsComment()).intValue() == 1){
            //商品自带的评论
            String copyComment = Tools.getStr(pyqgfkGoods.getCopyComment());
            String[] commentArr = copyComment.split("\\|");//"|"的转义字符为u007C
            if(commentArr != null && commentArr.length > 0){
                for (String comment : commentArr){
                    if(StringUtils.isNotBlank(comment)){
                        commentList.add(comment);
                    }
                }
            }
        }

        //自动发圈任务自定义评论
        String commentContent = Tools.getStr(pyqAutoConfig.getCommentContent());
        commentContent = commentContent.replace("[商品标题]",Tools.getStr(pyqgfkGoods.getItemtitle()))
                .replace("[文案]",Tools.getStr(pyqgfkGoods.getCopyContent()))
                .replace("[原价]",  String.valueOf(itemprice.doubleValue()))
                .replace("[券后价]", String.valueOf(itemendprice.doubleValue()));
        //追加页面自定义评论
        List<String> commentContentList =  JSONArray.parseArray(commentContent, String.class);
        if(commentContentList != null && commentContentList.size() > 0){
            for(String demo : commentContentList){
                if(StringUtils.isNotBlank(demo)){
                    commentList.add(demo);
                }
            }
        }

        //去空评论
        commentList.removeIf(s -> StringUtils.isBlank(s));

        //新评论(商品自带的评论+任务配置的评论)
        String comment_new = JSONObject.toJSONString(commentList);

        //替换随机字符串
        comment_new = MsgSplitUtil.replaceRandomStrArgs(comment_new);

        //替换随机表情
        while (comment_new.contains("[随机表情]")){
            comment_new = comment_new.replaceFirst("\\[随机表情\\]", Tools.getStr(EmojiUtil.getRandomEmoji()));
        }
        pyqJobDetail.setCommentContent(comment_new);

        //关键词过滤
        String ignore = pyqAutoConfig.getIgnore();
        if(StringUtils.isNotBlank(ignore)){
            try {
                List<String> ignoreList = JSONObject.parseArray(ignore, String.class);
                if(ignoreList != null && ignoreList.size() > 0){
                    for (String ignoreKey : ignoreList){
                        if(content.contains(ignoreKey)){
                            return null;
                        }
                        if(comment_new.contains(ignoreKey)){
                            return null;
                        }
                    }
                }
            }catch (Exception e){

            }
        }

        //是否开启插入随机表情
        Integer emoji = Tools.getInteger(pyqAutoConfig.getEmoji());
        if(emoji.intValue() == 1){ //开启插入随机表情
            //朋友圈内容前后各插2个
            //content = EmojiUtil.getRandomEmoji() + EmojiUtil.getRandomEmoji() + content + EmojiUtil.getRandomEmoji() + EmojiUtil.getRandomEmoji();
            //朋友圈内容结尾插2个
            content = content + EmojiUtil.getRandomEmoji() + EmojiUtil.getRandomEmoji();

            pyqJobDetail.setContent(content);
            //评论前后各插一个
//            List<String> comment_newList_emoji = JSONObject.parseArray(comment_new, String.class);
//            if(comment_newList_emoji != null && comment_newList_emoji.size() > 0) {
//                //评论前后各插一个
//                //List<String> list1 = comment_newList_emoji.stream().map(s -> EmojiUtil.getRandomEmoji() + s + EmojiUtil.getRandomEmoji()).collect(Collectors.toList());
//                //评论结尾插一个
//                List<String> list1 = comment_newList_emoji.stream().map(s -> s + EmojiUtil.getRandomEmoji()).collect(Collectors.toList());
//
//                comment_new = JSONObject.toJSONString(list1);
//                pyqJobDetail.setCommentContent(comment_new);
//            }
        }

        //先转链
        TurnlinkDto turnlinkDto = new TurnlinkDto();
        turnlinkDto.setMerId(pyqAutoConfig.getMerId());
        turnlinkDto.setPlatform(pyqgfkGoods.getPlatform());
        turnlinkDto.setCouponId(pyqJobDetail.getCouponId());
        turnlinkDto.setDevicePlanId(pyqAutoConfig.getDevicePlanId());
        turnlinkDto.setItemId(pyqJobDetail.getItemId());
        turnlinkDto.setDeviceUniqueId(deviceUniqueId);
        turnlinkDto.setGenerateShortUrl(1); //生成短链接
        SimpleTurnlinkVo simpleTurnlinkVo = getGoodInfo(turnlinkDto);

        //淘口令为空，则不发朋友圈
        if(StringUtils.isBlank(simpleTurnlinkVo.getBuyPwd()) || StringUtils.isBlank(simpleTurnlinkVo.getBuyUrl())){
            logger.error(JSONObject.toJSONString(new BizLog(LogBizTypeEnum.CONSOLE_PYQ_SEND_AUTO_VALUE,
                    pyqAutoConfig.getMerId(), device.getRecvmsgType(), deviceUniqueId,
                    "",0L,
                    "转链失败----未获取到淘口令或者购买链接")));
            return null;
        }

        //设置淘口令
        pyqJobDetail.setItemPwd(simpleTurnlinkVo.getBuyPwd());
        //设置打开淘宝url
        pyqJobDetail.setPwdShortUrl(simpleTurnlinkVo.getPwdShortUrl());

        //短语替换
        if(StringUtils.isNotBlank(pyqAutoConfig.getReplaceOld())){
            content = content.replace(pyqAutoConfig.getReplaceOld(), pyqAutoConfig.getReplaceNew());
            comment_new = comment_new.replace(pyqAutoConfig.getReplaceOld(), pyqAutoConfig.getReplaceNew());
        }

        //朋友圈内容替换变量
        content = content.replace("[购买链接]",Tools.getStr(simpleTurnlinkVo.getBuyUrl()))
                .replace("[淘口令]",Tools.getStr(simpleTurnlinkVo.getBuyPwd()));
        pyqJobDetail.setContent(content);
        //评论内容替换变量
        comment_new = comment_new.replace("[购买链接]",Tools.getStr(simpleTurnlinkVo.getBuyUrl()))
                .replace("[淘口令]",Tools.getStr(simpleTurnlinkVo.getBuyPwd()));
        pyqJobDetail.setCommentContent(comment_new);


        List<PyqJobDetail> pyqJobDetailList = new ArrayList<>();
        pyqJobDetail.setStatus(PyqJobDetailStatusEnum.NOSEND.getValue());
        pyqJobDetailList.add(pyqJobDetail);

        try{
            int time1 = DateUtil.getNowTime();
           // UzaiRespVo<Boolean> uzaiRespVo = uzaiBroadcastFeignService.pyqMsgPush(pyqJobDetailList);
            //elasticsearchUtil.addData(JSONObject.parseObject(JSONObject.toJSONString(pyqJobDetail)), EsIndexName.UZAI_PYQ_JOB_DETAIL, pyqJobDetail.getId());
            String uzai_pyq_job_detail = merchantService.getMechantOtherEsIndexName(EsIndexName.UZAI_PYQ_JOB_DETAIL, pyqJobDetail.getMerId());
            //保存发送消息
            List<Map<String, Object>> list = BeanMapUtil.objectList2ListMap(pyqJobDetailList);
            boolean result = elasticsearchUtilGroupMsg.addDataBatch(list, uzai_pyq_job_detail);
            int time2 = DateUtil.getNowTime();
            logger.info("自动发送朋友圈明细完成---usetime={}, 机器人唯一id={}, result={}", time2-time1, pyqJobDetail.getDeviceUniqueId(), JSONObject.toJSONString(result));
            if(result){ //成功发送
                //插入自动发送记录表中
                PyqAutoSend pyqAutoSend = new PyqAutoSend();
                pyqAutoSend.setId(IdWorker.getId());
                pyqAutoSend.setMerId(pyqAutoConfig.getMerId());
                pyqAutoSend.setAutoConfigId(pyqAutoConfig.getId());
                pyqAutoSend.setAutoConfigId(pyqAutoConfig.getId());
                pyqAutoSend.setDeviceType(DeviceTypeEnum.DT_PC_WECHAT.getKey());
                pyqAutoSend.setDeviceUniqueId(deviceUniqueId);
                pyqAutoSend.setSendTime(pyqAutoConfig.getSendTime());
                pyqAutoSend.setCreateTime(now);
                pyqAutoSend.setUpdateTime(now);
                pyqAutoSend.setType(pyqAutoConfig.getType());
                pyqAutoSend.setGoodsid(pyqgfkGoods.getId());
                pyqAutoSendMapper.insertSelective(pyqAutoSend);
            }
        }catch (Exception e){
            return null;
        }
        return pyqJobDetail;
    }

    /**
     * 自动发送好单库朋友圈商品明细
     * @author liuqi
     * @date 2021/8/25 11:38
     * @param pyqAutoConfig
     * @return null
     */
    private PyqJobDetail sendPyqJobDetailByHdkGoodsSync(PyqAutoConfig pyqAutoConfig, Long deviceUniqueId, Long pyqJobId, PyqHdkGoods pyqHdkGoods, int now){
        Device device = deviceService.findDeviceInfoByDeviceUniqueId(deviceUniqueId, null, pyqAutoConfig.getMerId());
        if(device == null){
            return null;
        }

        //赋值子任务明细
        PyqJobDetail pyqJobDetail = new PyqJobDetail() ;
        pyqJobDetail.setId(String.valueOf(IdWorker.getId()));
        pyqJobDetail.setVersion(0L);
        pyqJobDetail.setMerId(pyqAutoConfig.getMerId());
        pyqJobDetail.setJobId(pyqJobId);
        pyqJobDetail.setDeviceUniqueId(deviceUniqueId);
        pyqJobDetail.setDeviceType(device.getRecvmsgType());
        pyqJobDetail.setType(pyqAutoConfig.getType());
        pyqJobDetail.setPlatform(0);//淘宝
        pyqJobDetail.setSource(1);//发送来源（0手动发送；1自动发圈；2自动跟发）
        pyqJobDetail.setStartTime(pyqAutoConfig.getSendTime());
        pyqJobDetail.setSendTime(pyqAutoConfig.getSendTime());
        pyqJobDetail.setItemId(pyqHdkGoods.getItemid());
        pyqJobDetail.setCouponId(pyqHdkGoods.getCouponid());
        pyqJobDetail.setCouponVal(pyqHdkGoods.getCouponmoney());
        pyqJobDetail.setFinalPrice(pyqHdkGoods.getItemendprice());
        //图片
        List<String> imgList = new ArrayList<>();
        //添加商品图片
        String itempic = Tools.getStr(pyqHdkGoods.getItempic());
        if(StringUtils.isNotBlank(itempic)){
            try {
                List<String> itempicList = JSONArray.parseArray(itempic, String.class);
                if(itempicList != null && itempicList.size() > 0){
                    for (String item : itempicList){
                        if(StringUtils.isNotBlank(item)){
                            imgList.add(item);
                        }
                    }
                }
            }catch (Exception e){

            }
        }

        //好单库朋友圈自定义图片只有一张
        if(StringUtils.isNotBlank(pyqAutoConfig.getImgs())){
            try {
                if(imgList.size() > 8){
                    imgList = imgList.subList(0, 8);
                }
                imgList.addAll(JSONObject.parseArray(pyqAutoConfig.getImgs(), String.class));
            }catch (Exception e){

            }
        }
        if(imgList.size() > 9){
            imgList = imgList.subList(0, 9);
        }

        //2023-08-23 修改增加媒体信息
        List<FeedMedia> feedMediaList = new ArrayList<>();
        if(imgList != null && imgList.size() > 0){
            for (String img : imgList) {
                FeedMedia feedMedia = new FeedMedia();
                feedMedia.setUrl(img);
                feedMediaList.add(feedMedia);
            }
        }
        //2023-08-23 修改增加媒体信息
        pyqJobDetail.setImgs(null); //新协议imgs已放弃
        pyqJobDetail.setFeedMediaList(Tools.getStrNull(JSONObject.toJSONString(feedMediaList)));
        pyqJobDetail.setAttachType(2); //好单库只能发图文
        pyqJobDetail.setPyqVideoNumber(null);

        pyqJobDetail.setCreateTime(now);
        pyqJobDetail.setUpdateTime(now);

        //朋友圈内容
        //朋友圈内容替换变量
        String content = Tools.getStr(pyqAutoConfig.getContent());
        //券后价
        Double itemendprice = Tools.getDouble(pyqHdkGoods.getItemendprice());
        //优惠券金额
        Double couponmoney = Tools.getDouble(pyqHdkGoods.getCouponmoney());
        //原价 itemprice
        Double itemprice = Tools.getDouble(pyqHdkGoods.getItemprice());
        content = content.replace("[商品标题]",Tools.getStr(pyqHdkGoods.getItemtitle()))
                .replace("[文案]",Tools.getStr(pyqHdkGoods.getCopyContent()))
                .replace("[原价]",  String.valueOf(itemprice.doubleValue()))
                .replace("[券后价]", String.valueOf(itemendprice.doubleValue()));
        //替换随机字符串
        content = MsgSplitUtil.replaceRandomStrArgs(content);
        //替换随机表情
        while (content.contains("[随机表情]")){
            content = content.replaceFirst("\\[随机表情\\]", Tools.getStr(EmojiUtil.getRandomEmoji()));
        }

        pyqJobDetail.setContent(content);

        //评论内容替换变量
        List<String> commentList = new ArrayList<>();

        //是否发送商品自带评论 1-开启
        if(Tools.getInteger(pyqAutoConfig.getGoodsComment()).intValue() == 1){
            //商品自带的评论
            String copyComment = Tools.getStr(pyqHdkGoods.getCopyComment());
            String[] commentArr = copyComment.split("\\|");//"|"的转义字符为u007C
            if(commentArr != null && commentArr.length > 0){
                for (String comment : commentArr){
                    if(StringUtils.isNotBlank(comment)){
                        commentList.add(comment);
                    }
                }
            }
        }

        //自动发圈任务自定义评论
        String commentContent = Tools.getStr(pyqAutoConfig.getCommentContent());
        commentContent = commentContent.replace("[商品标题]",Tools.getStr(pyqHdkGoods.getItemtitle()))
                .replace("[文案]",Tools.getStr(pyqHdkGoods.getCopyContent()))
                .replace("[原价]",  String.valueOf(itemprice.doubleValue()))
                .replace("[券后价]", String.valueOf(itemendprice.doubleValue()));
        //追加页面自定义评论
        List<String> commentContentList =  JSONArray.parseArray(commentContent, String.class);
        if(commentContentList != null && commentContentList.size() > 0){
            for(String demo : commentContentList){
                if(StringUtils.isNotBlank(demo)){
                    commentList.add(demo);
                }
            }
        }

        //去空评论
        commentList.removeIf(s -> StringUtils.isBlank(s));

        //新评论(商品自带的评论+任务配置的评论)
        String comment_new = JSONObject.toJSONString(commentList);

        //替换随机字符串
        comment_new = MsgSplitUtil.replaceRandomStrArgs(comment_new);

        //替换随机表情
        while (comment_new.contains("[随机表情]")){
            comment_new = comment_new.replaceFirst("\\[随机表情\\]", Tools.getStr(EmojiUtil.getRandomEmoji()));
        }
        pyqJobDetail.setCommentContent(comment_new);

        //关键词过滤
        String ignore = pyqAutoConfig.getIgnore();
        if(StringUtils.isNotBlank(ignore)){
            try {
                List<String> ignoreList = JSONObject.parseArray(ignore, String.class);
                if(ignoreList != null && ignoreList.size() > 0){
                    for (String ignoreKey : ignoreList){
                        if(content.contains(ignoreKey)){
                            return null;
                        }
                        if(comment_new.contains(ignoreKey)){
                            return null;
                        }
                    }
                }
            }catch (Exception e){

            }
        }

        //是否开启插入随机表情
        Integer emoji = Tools.getInteger(pyqAutoConfig.getEmoji());
        if(emoji.intValue() == 1){ //开启插入随机表情
            //朋友圈内容前后各插2个
            //content = EmojiUtil.getRandomEmoji() + EmojiUtil.getRandomEmoji() + content + EmojiUtil.getRandomEmoji() + EmojiUtil.getRandomEmoji();
            //朋友圈内容结尾插2个
            content = content + EmojiUtil.getRandomEmoji() + EmojiUtil.getRandomEmoji();

            pyqJobDetail.setContent(content);
            //评论前后各插一个
//            List<String> comment_newList_emoji = JSONObject.parseArray(comment_new, String.class);
//            if(comment_newList_emoji != null && comment_newList_emoji.size() > 0) {
//                //评论前后各插一个
//                //List<String> list1 = comment_newList_emoji.stream().map(s -> EmojiUtil.getRandomEmoji() + s + EmojiUtil.getRandomEmoji()).collect(Collectors.toList());
//                //评论结尾插一个
//                List<String> list1 = comment_newList_emoji.stream().map(s -> s + EmojiUtil.getRandomEmoji()).collect(Collectors.toList());
//
//                comment_new = JSONObject.toJSONString(list1);
//                pyqJobDetail.setCommentContent(comment_new);
//            }
        }

        //先转链
        TurnlinkDto turnlinkDto = new TurnlinkDto();
        turnlinkDto.setMerId(pyqAutoConfig.getMerId());
        turnlinkDto.setPlatform(pyqHdkGoods.getPlatform());
        turnlinkDto.setCouponId(pyqJobDetail.getCouponId());
        turnlinkDto.setDevicePlanId(pyqAutoConfig.getDevicePlanId());
        turnlinkDto.setItemId(pyqJobDetail.getItemId());
        turnlinkDto.setDeviceUniqueId(deviceUniqueId);
        turnlinkDto.setGenerateShortUrl(1); //生成短链接
        SimpleTurnlinkVo simpleTurnlinkVo = getGoodInfo(turnlinkDto);

        //淘口令为空，则不发朋友圈
        if(StringUtils.isBlank(simpleTurnlinkVo.getBuyPwd()) || StringUtils.isBlank(simpleTurnlinkVo.getBuyUrl())){
            logger.error(JSONObject.toJSONString(new BizLog(LogBizTypeEnum.CONSOLE_PYQ_SEND_AUTO_VALUE,
                    pyqAutoConfig.getMerId(), device.getRecvmsgType(), deviceUniqueId,
                    "",0L,
                    "转链淘口令为空，或者短链接为空")));
            return null;
        }

        //设置淘口令
        pyqJobDetail.setItemPwd(simpleTurnlinkVo.getBuyPwd());
        //设置打开淘宝url
        pyqJobDetail.setPwdShortUrl(simpleTurnlinkVo.getPwdShortUrl());

        //短语替换
        if(StringUtils.isNotBlank(pyqAutoConfig.getReplaceOld())){
            content = content.replace(pyqAutoConfig.getReplaceOld(), pyqAutoConfig.getReplaceNew());
            comment_new = comment_new.replace(pyqAutoConfig.getReplaceOld(), pyqAutoConfig.getReplaceNew());
        }

        //朋友圈内容替换变量
        content = content.replace("[购买链接]",Tools.getStr(simpleTurnlinkVo.getBuyUrl()))
                .replace("[淘口令]",Tools.getStr(simpleTurnlinkVo.getBuyPwd()));
        pyqJobDetail.setContent(content);
        //评论内容替换变量
        comment_new = comment_new.replace("[购买链接]",Tools.getStr(simpleTurnlinkVo.getBuyUrl()))
                .replace("[淘口令]",Tools.getStr(simpleTurnlinkVo.getBuyPwd()));
        pyqJobDetail.setCommentContent(comment_new);

        List<PyqJobDetail> pyqJobDetailList = new ArrayList<>();
        pyqJobDetail.setStatus(PyqJobDetailStatusEnum.NOSEND.getValue());
        pyqJobDetailList.add(pyqJobDetail);

        try{
            int time1 = DateUtil.getNowTime();
            //20240112修改，将调用微服务保持朋友圈发送记录修改成直接调用ES保存
            //UzaiRespVo<Boolean> uzaiRespVo = uzaiBroadcastFeignService.pyqMsgPush(pyqJobDetailList);
            //elasticsearchUtil.addData(JSONObject.parseObject(JSONObject.toJSONString(pyqJobDetail)), EsIndexName.UZAI_PYQ_JOB_DETAIL, pyqJobDetail.getId());
            //保存发送消息
            List<Map<String, Object>> list = BeanMapUtil.objectList2ListMap(pyqJobDetailList);
            String uzai_pyq_job_detail = merchantService.getMechantOtherEsIndexName(EsIndexName.UZAI_PYQ_JOB_DETAIL, pyqAutoConfig.getMerId());
            boolean result = elasticsearchUtilGroupMsg.addDataBatch(list, uzai_pyq_job_detail);
            int time2 = DateUtil.getNowTime();
            logger.info("自动发送朋友圈明细完成---usetime={}, 机器人唯一id={}, result={}", time2-time1, pyqJobDetail.getDeviceUniqueId(), JSONObject.toJSONString(result));
            if(result){ //成功发送
                //插入自动发送记录表中
                PyqAutoSend pyqAutoSend = new PyqAutoSend();
                pyqAutoSend.setId(IdWorker.getId());
                pyqAutoSend.setMerId(pyqAutoConfig.getMerId());
                pyqAutoSend.setAutoConfigId(pyqAutoConfig.getId());
                pyqAutoSend.setDeviceType(DeviceTypeEnum.DT_PC_WECHAT.getKey());
                pyqAutoSend.setDeviceUniqueId(deviceUniqueId);
                pyqAutoSend.setSendTime(pyqAutoConfig.getSendTime());
                pyqAutoSend.setCreateTime(now);
                pyqAutoSend.setUpdateTime(now);
                pyqAutoSend.setType(pyqAutoConfig.getType());
                pyqAutoSend.setGoodsid(pyqHdkGoods.getId());
                pyqAutoSendMapper.insertSelective(pyqAutoSend);
            }
        }catch (Exception e){
            return null;
        }
        return pyqJobDetail;
    }

    /**
     * 自动发送老林云朋友圈商品明细
     * @author liuqi
     * @date 2021/8/25 11:38
     * @param pyqAutoConfig
     * @return null
     */
    private PyqJobDetail sendPyqJobDetailByLlyGoodsSync(PyqAutoConfig pyqAutoConfig, Long deviceUniqueId, Long pyqJobId, PyqLlyGoods pyqLlyGoods, int now, Long domain){
        Device device = deviceService.findDeviceInfoByDeviceUniqueId(deviceUniqueId, null, pyqAutoConfig.getMerId());
        if(device == null){
            return null;
        }

        //赋值子任务明细
        PyqJobDetail pyqJobDetail = new PyqJobDetail() ;
        pyqJobDetail.setId(String.valueOf(IdWorker.getId()));
        pyqJobDetail.setVersion(0L);
        pyqJobDetail.setMerId(pyqAutoConfig.getMerId());
        pyqJobDetail.setJobId(pyqJobId);
        pyqJobDetail.setStatus(PyqJobDetailStatusEnum.NOSEND.getValue());
        pyqJobDetail.setDeviceUniqueId(deviceUniqueId);
        pyqJobDetail.setDeviceType(device.getRecvmsgType());
        pyqJobDetail.setType(pyqAutoConfig.getType());
        pyqJobDetail.setPlatform(0);//淘宝
        pyqJobDetail.setSource(1);//发送来源（0手动发送；1自动发圈；2自动跟发）
        pyqJobDetail.setStartTime(pyqAutoConfig.getSendTime());
        pyqJobDetail.setSendTime(pyqAutoConfig.getSendTime());

        //图片
        List<String> imgList = new ArrayList<>();

        pyqJobDetail.setItemId(String.valueOf(pyqLlyGoods.getId()));

        //添加商品图片
        String itempic = Tools.getStr(pyqLlyGoods.getPic());
        if(StringUtils.isNotBlank(itempic)){
            try {
                List<String> itempicList = JSONArray.parseArray(itempic, String.class);
                if(itempicList != null && itempicList.size() > 0){
                    for (String item : itempicList){
                        if(StringUtils.isNotBlank(item)){
                            imgList.add(item);
                        }
                    }
                }
            }catch (Exception e){

            }
        }

        //老林库自定义图片只能一张
        if(StringUtils.isNotBlank(pyqAutoConfig.getImgs())){
            try {
                if(imgList.size() > 8){
                    imgList = imgList.subList(0, 8);
                }
                imgList.addAll(JSONObject.parseArray(pyqAutoConfig.getImgs(), String.class));
            }catch (Exception e){

            }
        }

        if(imgList.size() > 9){
            imgList = imgList.subList(0, 9);
        }

        pyqJobDetail.setImgs(Tools.getStrEmpty(JSONObject.toJSONString(imgList)));

        //2023-08-08 修改增加媒体信息
        if(imgList != null && imgList.size() > 0){
            List<FeedMedia> feedMediaList = new ArrayList<>();
            for (String img : imgList) {
                FeedMedia feedMedia = new FeedMedia();
                feedMedia.setUrl(img);
                feedMediaList.add(feedMedia);
            }
            pyqJobDetail.setFeedMediaList(Tools.getStrEmpty(JSONObject.toJSONString(feedMediaList)));
        }

        pyqJobDetail.setCreateTime(now);
        pyqJobDetail.setUpdateTime(now);

        //朋友圈内容
        //朋友圈内容替换变量
        String content = Tools.getStr(pyqAutoConfig.getContent());

        content = content.replace("[商品标题]",Tools.getStr(pyqLlyGoods.getTitle()))
                .replace("[文案]",Tools.getStr(pyqLlyGoods.getContent()));
        //替换随机字符串
        content = MsgSplitUtil.replaceRandomStrArgs(content);
        //替换随机表情
        while (content.contains("[随机表情]")){
            content = content.replaceFirst("\\[随机表情\\]", Tools.getStr(EmojiUtil.getRandomEmoji()));
        }

        pyqJobDetail.setContent(content);

        //评论内容替换变量
        List<String> commentList = new ArrayList<>();

        //是否发送商品自带评论 1-开启
        if(Tools.getInteger(pyqAutoConfig.getGoodsComment()).intValue() == 1){
            //老林云自带的评论
            String description = Tools.getStr(pyqLlyGoods.getDescription());
            try{
                List<String> descriptionList =JSONObject.parseArray(description, String.class);
                if(descriptionList != null && descriptionList.size() > 0){
                    for (String demo : descriptionList){
                        if(StringUtils.isNotBlank(demo)){
                            commentList.add(demo);
                        }
                    }
                }
            }catch (Exception e){
                logger.error("--老林云商品评论转JSON错误--");
            }
        }

        //自动发圈任务自定义评论
        String commentContent = Tools.getStr(pyqAutoConfig.getCommentContent());
        commentContent = commentContent.replace("[商品标题]",Tools.getStr(pyqLlyGoods.getTitle()))
                .replace("[文案]",Tools.getStr(pyqLlyGoods.getContent()));
        //追加页面自定义评论
        List<String> commentContentList =  JSONArray.parseArray(commentContent, String.class);
        if(commentContentList != null && commentContentList.size() > 0){
            for(String demo : commentContentList){
                if(StringUtils.isNotBlank(demo)){
                    commentList.add(demo);
                }
            }
        }

        //去空评论
        commentList.removeIf(s -> StringUtils.isBlank(s));

        //新评论(商品自带的评论+任务配置的评论)
        String comment_new = JSONObject.toJSONString(commentList);

        //替换随机字符串
        comment_new = MsgSplitUtil.replaceRandomStrArgs(comment_new);

        //替换随机表情
        while (comment_new.contains("[随机表情]")){
            comment_new = comment_new.replaceFirst("\\[随机表情\\]", Tools.getStr(EmojiUtil.getRandomEmoji()));
        }
        pyqJobDetail.setCommentContent(comment_new);

        //关键词过滤
        String ignore = pyqAutoConfig.getIgnore();
        if(StringUtils.isNotBlank(ignore)){
            try {
                List<String> ignoreList = JSONObject.parseArray(ignore, String.class);
                if(ignoreList != null && ignoreList.size() > 0){
                    for (String ignoreKey : ignoreList){
                        if(content.contains(ignoreKey)){
                            return null;
                        }
                        if(comment_new.contains(ignoreKey)){
                            return null;
                        }
                    }
                }
            }catch (Exception e){

            }
        }

        //短语替换
        if(StringUtils.isNotBlank(pyqAutoConfig.getReplaceOld())){
            content = content.replace(pyqAutoConfig.getReplaceOld(), pyqAutoConfig.getReplaceNew());
            comment_new = comment_new.replace(pyqAutoConfig.getReplaceOld(), pyqAutoConfig.getReplaceNew());
        }


        //是否开启插入随机表情
        Integer emoji = Tools.getInteger(pyqAutoConfig.getEmoji());
        if(emoji.intValue() == 1){ //开启插入随机表情
            //朋友圈内容前后各插2个
            //content = EmojiUtil.getRandomEmoji() + EmojiUtil.getRandomEmoji() + content + EmojiUtil.getRandomEmoji() + EmojiUtil.getRandomEmoji();
            //朋友圈内容结尾插2个
            content = content + EmojiUtil.getRandomEmoji() + EmojiUtil.getRandomEmoji();
            pyqJobDetail.setContent(content);
            //评论前后各插一个
//            List<String> comment_newList_emoji = JSONObject.parseArray(comment_new, String.class);
//            if(comment_newList_emoji != null && comment_newList_emoji.size() > 0) {
//                //评论前后各插一个
//                //List<String> list1 = comment_newList_emoji.stream().map(s -> EmojiUtil.getRandomEmoji() + s + EmojiUtil.getRandomEmoji()).collect(Collectors.toList());
//                //评论结尾插一个
//                List<String> list1 = comment_newList_emoji.stream().map(s -> s + EmojiUtil.getRandomEmoji()).collect(Collectors.toList());
//                comment_new = JSONObject.toJSONString(list1);
//                pyqJobDetail.setCommentContent(comment_new);
//            }
        }

        //CMS配置域名
        String cmsDomain = "";
        Long mailDomain = Tools.getLong(domain);
        if(mailDomain.longValue() == 0){ //官方域名
            SysDomain sysDomain = sysDomainMapper.selectById(2L, 1L);
            if(sysDomain != null){
                cmsDomain = Tools.getStr(sysDomain.getSiteDomain());
            }
        }else{
            SysDomain sysDomain = sysDomainMapper.selectById(mailDomain, pyqAutoConfig.getMerId());
            if(sysDomain != null){
                cmsDomain = Tools.getStr(sysDomain.getSiteDomain());
            }
        }

        if(StringUtils.isBlank(cmsDomain)){ //官方域名
            logger.error("----老林云商品链接生成中间页功能----设备域名未配置---");
            return null;
        }

        String llyMiddlePageMethod = uzaiConsoleSysConfig.getLlyMiddlePageMethod();
        String shortLinkListStr = Tools.getStr(pyqLlyGoods.getShortlink());

        HashMap<String, List<LlyMiddleDetail>> llyMiddleDetailHashMap = JSONObject.parseObject(pyqLlyGoods.getData(), new TypeReference<HashMap<String, List<LlyMiddleDetail>>>(){});
        if(llyMiddleDetailHashMap != null){
            //评论内容替换变量
            if(StringUtils.isNotBlank(shortLinkListStr)){
                List<String> shortLinkList = JSONObject.parseArray(shortLinkListStr, String.class);
                if(shortLinkList != null){
                    for(String shortLink : shortLinkList){
                        String middPageUrl = cmsDomain + "/" + llyMiddlePageMethod;
                        if(StringUtils.isNotBlank(shortLink) && StringUtils.isNotBlank(middPageUrl)){
                            //封装插入到中间页内容
                            List<LlyMiddleDetail> llyMiddleDetailList_new = new ArrayList<>();
                            //List<LlyMiddleDetail> llyMiddleDetailList = JSONObject.parseArray(pyqLlyGoods.getData(), LlyMiddleDetail.class);
                            List<LlyMiddleDetail> llyMiddleDetailList = llyMiddleDetailHashMap.get(shortLink);
                            if(llyMiddleDetailList != null && llyMiddleDetailList.size() > 0){
                                for (LlyMiddleDetail llyMiddleDetail : llyMiddleDetailList){
                                    //中间页内容
                                    String data_content = llyMiddleDetail.getContent();
                                    if(StringUtils.isNotBlank(data_content)){
                                        String itemId = llyMiddleDetail.getItemId();
                                        String bizSceneId = llyMiddleDetail.getBizSceneId();
                                        if(StringUtils.isNotBlank(itemId)){
                                            //转链生成新的购买淘口令，保持到老林云商品中间页数据当中
                                            TurnlinkDto turnlinkDto = new TurnlinkDto();
                                            turnlinkDto.setMerId(pyqAutoConfig.getMerId());
                                            turnlinkDto.setPlatform(0); //老林云只有淘宝
                                            turnlinkDto.setCouponId(null);
                                            turnlinkDto.setDevicePlanId(pyqAutoConfig.getDevicePlanId());
                                            turnlinkDto.setDeviceUniqueId(deviceUniqueId);
                                            turnlinkDto.setItemId(itemId);
                                            turnlinkDto.setBizSceneId(bizSceneId);
                                            turnlinkDto.setGenerateShortUrl(0); //不生产短链接
                                            SimpleTurnlinkVo simpleTurnlinkVo = getGoodInfo(turnlinkDto);
                                            String pwd_new = simpleTurnlinkVo.getPurePwd();
                                            //淘口令为空，则不发朋友圈
                                            if(StringUtils.isBlank(pwd_new)){
                                                logger.error(JSONObject.toJSONString(new BizLog(LogBizTypeEnum.CONSOLE_PYQ_SEND_AUTO_VALUE,
                                                        pyqAutoConfig.getMerId(), device.getRecvmsgType(), deviceUniqueId,
                                                        "",0L,
                                                        "转链失败，淘口令为空")));
                                                return null;
                                            }else{
                                                String data_content_new = data_content.replace(itemId, pwd_new);
                                                llyMiddleDetail.setContent(data_content_new);
                                                llyMiddleDetail.setPwd(pwd_new);
                                            }
                                        }
                                    }

                                    llyMiddleDetailList_new.add(llyMiddleDetail);

                                }
                            }

                            String data_new = JSONObject.toJSONString(llyMiddleDetailList_new);
                            Long id = IdWorker.getId();
                            middPageUrl = middPageUrl + id;

                            //生成短链接
                            GenerateShortUrlDto generateShortUrlDto = new GenerateShortUrlDto();
                            generateShortUrlDto.setMerId(pyqAutoConfig.getMerId());
                            generateShortUrlDto.setUrl(middPageUrl);
                            UzaiRespVo<String> uzaiRespVo = uzaiTurnlinkFeignService.generateShortUrl(generateShortUrlDto);
                            logger.info("---老林云商品生成中间页生成短链接---dto={},result={}",JSONObject.toJSONString(generateShortUrlDto), JSONObject.toJSONString(uzaiRespVo));
                            if(uzaiRespVo != null && uzaiRespVo.getCode() == 200){
                                //获取生成的短链接
                                middPageUrl = uzaiRespVo.getData();
                                //短链接为空，则不发送
                                if(StringUtils.isBlank(middPageUrl)){
                                    return null;
                                }
                            }

                            //保持老林云商品中间页链接
                            PyqLlyShortlink pyqLlyShortlink = new PyqLlyShortlink();
                            pyqLlyShortlink.setId(id);
                            pyqLlyShortlink.setGoodsid(pyqLlyGoods.getId());
                            pyqLlyShortlink.setData(data_new);
                            pyqLlyShortlink.setCreateTime(now);
                            pyqLlyShortlink.setUpdateTime(now);
                            pyqLlyShortlink.setUrl(middPageUrl);
                            pyqLlyShortlinkMapper.insertSelective(pyqLlyShortlink);

                            comment_new = comment_new.replace(shortLink, middPageUrl);
                            pyqJobDetail.setCommentContent(comment_new);
                        }
                    }
                }
            }
        }

        List<PyqJobDetail> pyqJobDetailList = new ArrayList<>();
        pyqJobDetailList.add(pyqJobDetail);

        try{
            int time1 = DateUtil.getNowTime();
            // UzaiRespVo<Boolean> uzaiRespVo = uzaiBroadcastFeignService.pyqMsgPush(pyqJobDetailList);
            //elasticsearchUtil.addData(JSONObject.parseObject(JSONObject.toJSONString(pyqJobDetail)), EsIndexName.UZAI_PYQ_JOB_DETAIL, pyqJobDetail.getId());
            String uzai_pyq_job_detail = merchantService.getMechantOtherEsIndexName(EsIndexName.UZAI_PYQ_JOB_DETAIL, pyqJobDetail.getMerId());
            //保存发送消息
            List<Map<String, Object>> list = BeanMapUtil.objectList2ListMap(pyqJobDetailList);
            boolean result = elasticsearchUtilGroupMsg.addDataBatch(list, uzai_pyq_job_detail);
            int time2 = DateUtil.getNowTime();
            logger.info("自动发送朋友圈明细完成---usetime={}, 机器人唯一id={}, result={}", time2-time1, pyqJobDetail.getDeviceUniqueId(), JSONObject.toJSONString(result));
            if(result) { //成功发送
                //插入自动发送记录表中
                PyqAutoSend pyqAutoSend = new PyqAutoSend();
                pyqAutoSend.setId(IdWorker.getId());
                pyqAutoSend.setMerId(pyqAutoConfig.getMerId());
                pyqAutoSend.setAutoConfigId(pyqAutoConfig.getId());
                pyqAutoSend.setDeviceType(DeviceTypeEnum.DT_PC_WECHAT.getKey());
                pyqAutoSend.setDeviceUniqueId(deviceUniqueId);
                pyqAutoSend.setSendTime(pyqAutoConfig.getSendTime());
                pyqAutoSend.setCreateTime(now);
                pyqAutoSend.setUpdateTime(now);
                pyqAutoSend.setType(pyqAutoConfig.getType());
                pyqAutoSend.setGoodsid(pyqLlyGoods.getId());
                pyqAutoSendMapper.insertSelective(pyqAutoSend);
            }
        }catch (Exception e){
            return null;
        }
        return pyqJobDetail;
    }


    /**
     * 自动发送悠哉精品库商品朋友圈商品明细
     * @author liuqi
     * @date 2021/8/25 11:38
     * @param pyqAutoConfig
     * @return null
     */
    private PyqJobDetail sendPyqJobDetailByYzjpGoodsSync(PyqAutoConfig pyqAutoConfig, Long deviceUniqueId, Long pyqJobId, PyqLlyGoodsVo pyqLlyGoodsVo, int now, Long domain){

        Device device = deviceService.findDeviceInfoByDeviceUniqueId(deviceUniqueId, null,pyqAutoConfig.getMerId());
        if(device == null){
            return null;
        }

        //生成朋友圈悠哉精品库朋友圈明细
        PyqJobDetail pyqJobDetail = createPyqJobDetailByYzjpGoods(pyqAutoConfig, device, pyqJobId, pyqLlyGoodsVo, now, domain);
        if(pyqJobDetail != null){
            //发送朋友圈列表
            List<PyqJobDetail> pyqJobDetailList = new ArrayList<>();
            pyqJobDetailList.add(pyqJobDetail);
            // UzaiRespVo<Boolean> uzaiRespVo = uzaiBroadcastFeignService.pyqMsgPush(pyqJobDetailList);
            //elasticsearchUtil.addData(JSONObject.parseObject(JSONObject.toJSONString(pyqJobDetail)), EsIndexName.UZAI_PYQ_JOB_DETAIL, pyqJobDetail.getId());
            String uzai_pyq_job_detail = merchantService.getMechantOtherEsIndexName(EsIndexName.UZAI_PYQ_JOB_DETAIL, pyqJobDetail.getMerId());
            //保存发送消息
            List<Map<String, Object>> list = BeanMapUtil.objectList2ListMap(pyqJobDetailList);
            boolean result = elasticsearchUtilGroupMsg.addDataBatch(list, uzai_pyq_job_detail);
            logger.info("--调用自动发送朋友圈明细微服务接口-----机器人唯一id={}, result={}", pyqJobDetail.getDeviceUniqueId(), JSONObject.toJSONString(result));
            if(result){ //成功发送
                //判断商品发送成功，才修改曝光率
                if(pyqJobDetail.getStatus().intValue() == PyqJobDetailStatusEnum.NOSEND.getValue()){
                    //发送成功，修改精品库商品曝光量
                    GoodsUpdateExposureNumBySendPyqDto goodsUpdateExposureNumBySendPyqDto = new GoodsUpdateExposureNumBySendPyqDto();
                    goodsUpdateExposureNumBySendPyqDto.setId(pyqLlyGoodsVo.getId());
                    goodsUpdateExposureNumBySendPyqDto.setAddNum(1);
                    UzaiRespVo<Object> uzaiRespVo1 = uzaiBusinessFeignService.updateExposureNumBySendPyq(goodsUpdateExposureNumBySendPyqDto);
                    logger.info("---自动发送悠哉精品库商品朋友圈，修改商品曝光量，para={}, result={}",JSONObject.toJSONString(goodsUpdateExposureNumBySendPyqDto), JSONObject.toJSONString(uzaiRespVo1));

                    //插入自动发送记录表中
                    PyqAutoSend pyqAutoSend = new PyqAutoSend();
                    pyqAutoSend.setId(IdWorker.getId());
                    pyqAutoSend.setMerId(pyqAutoConfig.getMerId());
                    pyqAutoSend.setAutoConfigId(pyqAutoConfig.getId());
                    pyqAutoSend.setDeviceType(DeviceTypeEnum.DT_PC_WECHAT.getKey());
                    pyqAutoSend.setDeviceUniqueId(deviceUniqueId);
                    pyqAutoSend.setSendTime(pyqAutoConfig.getSendTime());
                    pyqAutoSend.setCreateTime(now);
                    pyqAutoSend.setUpdateTime(now);
                    pyqAutoSend.setType(pyqAutoConfig.getType());
                    pyqAutoSend.setGoodsid(pyqLlyGoodsVo.getId());
                    pyqAutoSendMapper.insertSelective(pyqAutoSend);
                }
            }else{
                logger.error(JSONObject.toJSONString(new BizLog(LogBizTypeEnum.CONSOLE_PYQ_SEND_AUTO_VALUE,
                        pyqAutoConfig.getMerId(), device.getRecvmsgType(), device.getId(),
                        "",0L,
                        "-调用自动发送朋友圈明细微服务接口失败")));
                //调用微服务保存朋友圈明细失败，则返回空明细
                return null;
            }
        }

        return pyqJobDetail;
    }


    /**
     * 生成悠哉精品库朋友圈明细
     * @author jitwxs
     * @date 2023/4/19 9:49
     * @return null
     */
    private PyqJobDetail createPyqJobDetailByYzjpGoods(PyqAutoConfig pyqAutoConfig, Device device, Long pyqJobId, PyqLlyGoodsVo pyqLlyGoodsVo, int now, Long domain){

        //赋值子任务明细
        PyqJobDetail pyqJobDetail = new PyqJobDetail() ;
        pyqJobDetail.setId(String.valueOf(IdWorker.getId()));
        pyqJobDetail.setVersion(0L);
        pyqJobDetail.setMerId(pyqAutoConfig.getMerId());
        pyqJobDetail.setJobId(pyqJobId);
        pyqJobDetail.setDeviceUniqueId(device.getId());
        pyqJobDetail.setDeviceType(device.getRecvmsgType());
        pyqJobDetail.setType(pyqAutoConfig.getType());
        pyqJobDetail.setCouponId(pyqLlyGoodsVo.getCouponId()); //优惠券金额
        pyqJobDetail.setCouponVal(pyqLlyGoodsVo.getCoupon());
        if(Tools.getInteger(pyqLlyGoodsVo.getPlatform()).intValue() == 1){//悠哉精选朋友圈拼多多商品
            pyqJobDetail.setPlatform(2); //拼多多
        }else if(Tools.getInteger(pyqLlyGoodsVo.getPlatform()).intValue() == 2){ //悠哉精选朋友圈京东商品
            pyqJobDetail.setPlatform(1); //淘宝
        }else{
            pyqJobDetail.setPlatform(pyqLlyGoodsVo.getPlatform());
        }

        pyqJobDetail.setSource(1);//发送来源（0手动发送；1自动发圈；2自动跟发）
        pyqJobDetail.setStartTime(pyqAutoConfig.getSendTime());
        pyqJobDetail.setSendTime(pyqAutoConfig.getSendTime());
        pyqJobDetail.setItemId(pyqLlyGoodsVo.getLlyid());
        pyqJobDetail.setItemHeaderId(pyqLlyGoodsVo.getGoodsHeaderId());
        pyqJobDetail.setItemTailId(StringUtils.isNotBlank(pyqLlyGoodsVo.getGoodsTailId())?pyqLlyGoodsVo.getGoodsTailId():pyqLlyGoodsVo.getLlyid());

        //2023-08-08 修改增加媒体信息
        //封装附件类型
        int attachType = 2; //默认图文
        //封装附件对象
        List<FeedMedia> feedMediaList = new ArrayList<>();
        //封装视频号信息
        String videoNumber = null;
        //封装朋友圈内容
        String content_goods = "";
        //朋友圈评论
        String description_goods = "";
        //附件模类型
        String materialType_job = pyqAutoConfig.getMaterialType();
        List<Integer> materialTypeList_job = JSONObject.parseArray(materialType_job, Integer.class);
        if(materialTypeList_job.containsAll(Lists.newArrayList(2,5))){     //自动发送任务包括所有，优先商品的视频号，没有则发送图文
            String materialType_goods = Tools.getStr(pyqLlyGoodsVo.getMaterialType());
            if(materialType_goods.contains("5")){ //有视频号
                //附件类型
                attachType = 5;
                //附件信息
                String mediaList = pyqLlyGoodsVo.getMediaList();
                feedMediaList = JSONObject.parseArray(mediaList, FeedMedia.class);
                //视频号信息
                videoNumber = Tools.getStr(pyqLlyGoodsVo.getPyqVideoNumber());
                //朋友圈内容
                content_goods = Tools.getStr(pyqLlyGoodsVo.getContentVideo());
                //评论
                description_goods = Tools.getStr(pyqLlyGoodsVo.getDescriptionVideo());
            }else{//无视频，只发图文
                //附件类型
                attachType = 2;
                //朋友圈内容
                content_goods = Tools.getStr(pyqLlyGoodsVo.getContent());
                //评论
                description_goods = Tools.getStr(pyqLlyGoodsVo.getDescription());
                //图片
                String goodsPic = Tools.getStr(pyqLlyGoodsVo.getPic());
                if(StringUtils.isNotBlank(goodsPic)){
                    try {
                        List<String> itempicList = JSONArray.parseArray(goodsPic, String.class);
                        if(itempicList != null && itempicList.size() > 0){
                            for (String item : itempicList){
                                if(StringUtils.isNotBlank(item)){
                                    FeedMedia feedMedia = new FeedMedia();
                                    feedMedia.setMediaType(2);
                                    feedMedia.setUrl(item);
                                    feedMediaList.add(feedMedia);
                                }
                            }
                        }
                    }catch (Exception e){

                    }
                }
            }
        }else if(materialTypeList_job.contains(2)){   //自动任务只发图文
            //附件类型
            attachType = 2;
            //朋友圈内容
            content_goods = Tools.getStr(pyqLlyGoodsVo.getContent());
            //评论
            description_goods = Tools.getStr(pyqLlyGoodsVo.getDescription());
            //图片
            String goodsPic = Tools.getStr(pyqLlyGoodsVo.getPic());
            if(StringUtils.isNotBlank(goodsPic)){
                try {
                    List<String> itempicList = JSONArray.parseArray(goodsPic, String.class);
                    if(itempicList != null && itempicList.size() > 0){
                        for (String item : itempicList){
                            if(StringUtils.isNotBlank(item)){
                                FeedMedia feedMedia = new FeedMedia();
                                feedMedia.setMediaType(2);
                                feedMedia.setUrl(item);
                                feedMediaList.add(feedMedia);
                            }
                        }
                    }
                }catch (Exception e){

                }
            }
        }else{//只发视频号
            //附件类型
            attachType = 5;
            //附件信息
            String mediaList = pyqLlyGoodsVo.getMediaList();
            feedMediaList = JSONObject.parseArray(mediaList, FeedMedia.class);
            //视频号信息
            videoNumber = Tools.getStr(pyqLlyGoodsVo.getPyqVideoNumber());
            //朋友圈内容
            content_goods = Tools.getStr(pyqLlyGoodsVo.getContentVideo());
            //评论
            description_goods = Tools.getStr(pyqLlyGoodsVo.getDescriptionVideo());
        }

        //判断发送附件类型，如果是图文，则需要判断是否添加自定义图片
        if(attachType == 2){ //图文
            //自定义图片不为空，则将自定义图片放到末尾
            if(StringUtils.isNotBlank(pyqAutoConfig.getImgs())){
                if(feedMediaList.size() > 8){
                    feedMediaList = feedMediaList.subList(0, 8);
                }

                List<String> imgList = JSONObject.parseArray(pyqAutoConfig.getImgs(), String.class);
                if(imgList != null && imgList.size() > 0){
                    for (String img : imgList) {
                        FeedMedia feedMedia = new FeedMedia();
                        feedMedia.setMediaType(2);
                        feedMedia.setUrl(img);
                        feedMediaList.add(feedMedia);
                    }
                }
            }

            if(feedMediaList.size() > 9){
                feedMediaList = feedMediaList.subList(0, 9);
            }
        }

        //新版朋友圈接口新增加字段
        pyqJobDetail.setAttachType(attachType);
        pyqJobDetail.setFeedMediaList(Tools.getStrNull(JSONObject.toJSONString(feedMediaList)));
        pyqJobDetail.setPyqVideoNumber(Tools.getStrNull(videoNumber));
        pyqJobDetail.setImgs(null);  //新版朋友圈接口，img不存放任何东西

        pyqJobDetail.setCreateTime(now);
        pyqJobDetail.setUpdateTime(now);

        //是否保存朋友圈商品发送记录
        boolean savePyqAutoSendFlag = false;

        //商品信息完整性判断，默认为正确
        //判断此商品信息是否正确。有商品id,评论不为空，内容不为空
        if(StringUtils.isBlank(pyqLlyGoodsVo.getLlyid()) || StringUtils.isBlank(pyqLlyGoodsVo.getContent()) || StringUtils.isBlank(pyqLlyGoodsVo.getDescription())){
            logger.error(JSONObject.toJSONString(new BizLog(LogBizTypeEnum.CONSOLE_PYQ_SEND_AUTO_VALUE,
                    pyqAutoConfig.getMerId(), device.getRecvmsgType(), device.getId(),
                    "",0L,
                    "自动发送悠哉精品库商品朋友圈失败，商品信息有误。商品id=" + pyqLlyGoodsVo.getLlyid())));

            //发送失败
            pyqJobDetail.setStatus(PyqJobDetailStatusEnum.SENDFAIL.getValue());
            pyqJobDetail.setFailMsg("商品缺少商品id、朋友圈内容、评论信息等信息");
            //插入自动发送记录表中
            PyqAutoSend pyqAutoSend = new PyqAutoSend();
            pyqAutoSend.setId(IdWorker.getId());
            pyqAutoSend.setMerId(pyqAutoConfig.getMerId());
            pyqAutoSend.setAutoConfigId(pyqAutoConfig.getId());
            pyqAutoSend.setDeviceType(DeviceTypeEnum.getById(device.getRecvmsgType()).getKey());
            pyqAutoSend.setDeviceUniqueId(device.getId());
            pyqAutoSend.setSendTime(pyqAutoConfig.getSendTime());
            pyqAutoSend.setCreateTime(now);
            pyqAutoSend.setUpdateTime(now);
            pyqAutoSend.setType(pyqAutoConfig.getType());
            pyqAutoSend.setGoodsid(pyqLlyGoodsVo.getId());
            pyqAutoSendMapper.insertSelective(pyqAutoSend);
            return pyqJobDetail;
        }


        //朋友圈内容
        //朋友圈内容替换变量
        String content = Tools.getStr(pyqAutoConfig.getContent());
        //如果任务内容的为空，则获取商品的内容
        if(StringUtils.isBlank(content)){
            content  = content_goods;
        }

        content = content.replace("[商品标题]",Tools.getStr(pyqLlyGoodsVo.getTitle()))
                .replace("[文案]",Tools.getStr(content_goods)) //商品的文案
                .replace("[原价]",String.valueOf(Tools.getDouble(pyqLlyGoodsVo.getOriginalPrice())))
                .replace("[券后价]",String.valueOf(Tools.getDouble(pyqLlyGoodsVo.getPostCouponPrice())));
        //替换随机字符串
        content = MsgSplitUtil.replaceRandomStrArgs(content);
        //替换随机表情
        while (content.contains("[随机表情]")){
            content = content.replaceFirst("\\[随机表情\\]", Tools.getStr(EmojiUtil.getRandomEmoji()));
        }

        pyqJobDetail.setContent(content);

        //评论内容替换变量
        List<String> commentList = new ArrayList<>();

        //先判断是否发送商品评论层数
        //老林云自带的评论
        List<String> descriptionList = null;
        String description = Tools.getStr(description_goods);
        if(StringUtils.isNotBlank(description)){
            try {
                descriptionList  = JSONObject.parseArray(description, String.class);
            }catch (Exception e){}
        }
        //商品有评论，判断配置方案里的评论信息
        if(descriptionList != null && descriptionList.size() > 0){
            //先判断配置方案中是否配置了商品评论层数
            List<Integer> goodsCommentLevelList = null;
            String goodsCommentLevel = pyqAutoConfig.getGoodsCommentLevel();
            if(StringUtils.isNotBlank(goodsCommentLevel)){
                try {
                    goodsCommentLevelList = JSONObject.parseArray(goodsCommentLevel, Integer.class);
                }catch (Exception e){}
            }
            //如果配置了发送商品评论层数，则优先处理，如果没有配置，则根据是否发送商品评论开光来判断
            if(goodsCommentLevelList != null && goodsCommentLevelList.size() > 0){
                for (int i = 0; i < goodsCommentLevelList.size(); i++) {
                    if(goodsCommentLevelList.get(i).intValue() == 1){ //开启，则发送评论
                        //查找符合条件的评论
                        String descriptionStr = null;
                        if(i == 0){ //评论
                            descriptionStr = getDescription(descriptionList, 0);
                        }else if(i == 1){ //购买链接
                            descriptionStr = getDescription(descriptionList, 1);
                        }else if(i == 2){ //口令
                            if(pyqAutoConfig.getType().intValue() == 2){ //淘宝
                                descriptionStr = getDescription(descriptionList, 2);
                            }
                        }
                        //如果不为空，则表示查询到了，则添加到评论列表中
                        if(StringUtils.isNotBlank(descriptionStr)){
                            commentList.add(descriptionStr);
                        }
                    }
                }
            }else{ //如果发送商品层数没值，则判断是否发送商品自带评论开关是否开启
                //是否发送商品自带评论 1-开启
                if (Tools.getInteger(pyqAutoConfig.getGoodsComment()).intValue() == 1) {
                    for (String demo : descriptionList) {
                        if (StringUtils.isNotBlank(demo)) {
                            commentList.add(demo);
                        }
                    }
                }
            }
        }

        //自动发圈任务自定义评论
        String commentContent = Tools.getStr(pyqAutoConfig.getCommentContent());
        //追加页面自定义评论
        List<String> commentContentList =  JSONArray.parseArray(commentContent, String.class);
        if(commentContentList != null && commentContentList.size() > 0){
            for(String demo : commentContentList){
                if(StringUtils.isNotBlank(demo)){
                    commentList.add(demo);
                }
            }
        }

        //去空评论
        commentList.removeIf(s -> StringUtils.isBlank(s));

        //新评论(商品自带的评论+任务配置的评论)
        String comment_new = JSONObject.toJSONString(commentList);

        comment_new = comment_new.replace("[商品标题]",Tools.getStr(pyqLlyGoodsVo.getTitle()))
                .replace("[文案]",Tools.getStr(content_goods))
                .replace("[原价]",String.valueOf(Tools.getDouble(pyqLlyGoodsVo.getOriginalPrice())))
                .replace("[券后价]",String.valueOf(Tools.getDouble(pyqLlyGoodsVo.getPostCouponPrice())));

        //替换随机字符串
        comment_new = MsgSplitUtil.replaceRandomStrArgs(comment_new);

        //替换随机表情
        while (comment_new.contains("[随机表情]")){
            comment_new = comment_new.replaceFirst("\\[随机表情\\]", Tools.getStr(EmojiUtil.getRandomEmoji()));
        }
        pyqJobDetail.setCommentContent(comment_new);

        //关键词过滤
        String ignore = pyqAutoConfig.getIgnore();
        if(StringUtils.isNotBlank(ignore)){
            try {
                List<String> ignoreList = JSONObject.parseArray(ignore, String.class);
                if(ignoreList != null && ignoreList.size() > 0){
                    for (String ignoreKey : ignoreList){
                        if(content.contains(ignoreKey)){
                            logger.error(JSONObject.toJSONString(new BizLog(LogBizTypeEnum.CONSOLE_PYQ_SEND_AUTO_VALUE,
                                    pyqAutoConfig.getMerId(), device.getRecvmsgType(), device.getId(),
                                    "",0L,
                                    "关键词过滤；朋友圈内容为：" + content)));
                            //发送失败
                            pyqJobDetail.setStatus(PyqJobDetailStatusEnum.SENDFAIL.getValue());
                            pyqJobDetail.setFailMsg("朋友圈内容触发过滤关键词["+ignoreKey+"]");

                            //插入自动发送记录表中
                            PyqAutoSend pyqAutoSend = new PyqAutoSend();
                            pyqAutoSend.setId(IdWorker.getId());
                            pyqAutoSend.setMerId(pyqAutoConfig.getMerId());
                            pyqAutoSend.setAutoConfigId(pyqAutoConfig.getId());
                            pyqAutoSend.setDeviceType(DeviceTypeEnum.getById(device.getRecvmsgType()).getKey());
                            pyqAutoSend.setDeviceUniqueId(device.getId());
                            pyqAutoSend.setSendTime(pyqAutoConfig.getSendTime());
                            pyqAutoSend.setCreateTime(now);
                            pyqAutoSend.setUpdateTime(now);
                            pyqAutoSend.setType(pyqAutoConfig.getType());
                            pyqAutoSend.setGoodsid(pyqLlyGoodsVo.getId());
                            pyqAutoSendMapper.insertSelective(pyqAutoSend);

                            return pyqJobDetail;
                        }

                        if(comment_new.contains(ignoreKey)){
                            logger.error(JSONObject.toJSONString(new BizLog(LogBizTypeEnum.CONSOLE_PYQ_SEND_AUTO_VALUE,
                                    pyqAutoConfig.getMerId(), device.getRecvmsgType(), device.getId(),
                                    "",0L,
                                    "关键词过滤；评论为：" + comment_new)));
                            //发送失败
                            pyqJobDetail.setStatus(PyqJobDetailStatusEnum.SENDFAIL.getValue());
                            pyqJobDetail.setFailMsg("朋友圈评论触发过滤关键词["+ignoreKey+"]");

                            //插入自动发送记录表中
                            PyqAutoSend pyqAutoSend = new PyqAutoSend();
                            pyqAutoSend.setId(IdWorker.getId());
                            pyqAutoSend.setMerId(pyqAutoConfig.getMerId());
                            pyqAutoSend.setAutoConfigId(pyqAutoConfig.getId());
                            pyqAutoSend.setDeviceType(DeviceTypeEnum.getById(device.getRecvmsgType()).getKey());
                            pyqAutoSend.setDeviceUniqueId(device.getId());
                            pyqAutoSend.setSendTime(pyqAutoConfig.getSendTime());
                            pyqAutoSend.setCreateTime(now);
                            pyqAutoSend.setUpdateTime(now);
                            pyqAutoSend.setType(pyqAutoConfig.getType());
                            pyqAutoSend.setGoodsid(pyqLlyGoodsVo.getId());
                            pyqAutoSendMapper.insertSelective(pyqAutoSend);

                            return pyqJobDetail;
                        }
                    }
                }
            }catch (Exception e){

            }
        }

        //是否开启插入随机表情
        Integer emoji = Tools.getInteger(pyqAutoConfig.getEmoji());
        if(emoji.intValue() == 1){ //开启插入随机表情
            //朋友圈内容前后各插2个
            //content = EmojiUtil.getRandomEmoji() + EmojiUtil.getRandomEmoji() + content + EmojiUtil.getRandomEmoji() + EmojiUtil.getRandomEmoji();
            //朋友圈内容结尾插2个
            content = content + EmojiUtil.getRandomEmoji() + EmojiUtil.getRandomEmoji();

            pyqJobDetail.setContent(content);
            //评论前后各插一个
//            List<String> comment_newList_emoji = JSONObject.parseArray(comment_new, String.class);
//            if(comment_newList_emoji != null && comment_newList_emoji.size() > 0) {
//                //评论前后各插一个
//                //List<String> list1 = comment_newList_emoji.stream().map(s -> EmojiUtil.getRandomEmoji() + s + EmojiUtil.getRandomEmoji()).collect(Collectors.toList());
//                //评论结尾插一个
//                List<String> list1 = comment_newList_emoji.stream().map(s -> s + EmojiUtil.getRandomEmoji()).collect(Collectors.toList());
//
//                comment_new = JSONObject.toJSONString(list1);
//                pyqJobDetail.setCommentContent(comment_new);
//            }
        }

        //替换今日合集变量
        //判断是否有今日合集变量，如果有，则商品的购买连接url地址也需要拼接今日合集参数
        boolean todaySendListFlag = false;
        if(content.contains("[今日合集]") || comment_new.contains("[今日合集]")){
            todaySendListFlag = true; //有今日合集
            //CMS配置域名
            String cmsDomain = "";
            Long mailDomain = Tools.getLong(domain);
            if(mailDomain.longValue() == 0){ //官方域名
                SysDomain sysDomain = sysDomainMapper.selectById(2L, 1L);
                if(sysDomain != null){
                    cmsDomain = Tools.getStr(sysDomain.getSiteDomain());
                }
            }else{
                SysDomain sysDomain = sysDomainMapper.selectById(mailDomain, pyqAutoConfig.getMerId());
                if(sysDomain != null){
                    cmsDomain = Tools.getStr(sysDomain.getSiteDomain());
                }
            }

            if(StringUtils.isBlank(cmsDomain)){ //官方域名
                logger.error(JSONObject.toJSONString(new BizLog(LogBizTypeEnum.CONSOLE_PYQ_SEND_AUTO_VALUE,
                        pyqAutoConfig.getMerId(), device.getRecvmsgType(), device.getId(),
                        "",0L,
                        "设备方案未配置域名")));
                //发送失败
                pyqJobDetail.setStatus(PyqJobDetailStatusEnum.SENDFAIL.getValue());
                pyqJobDetail.setFailMsg("设备方案未配置域名");
                return pyqJobDetail;
            }

            String middPageUrl = cmsDomain + "/" + uzaiConsoleSysConfig.getPyqTodaySendListUrl();
            middPageUrl = String.format(middPageUrl, pyqJobDetail.getId(), pyqJobDetail.getMerId());
            //生成短链接
            GenerateShortUrlDto generateShortUrlDto = new GenerateShortUrlDto();
            generateShortUrlDto.setMerId(pyqAutoConfig.getMerId());
            generateShortUrlDto.setUrl(middPageUrl);
            generateShortUrlDto.setIgnoreShortUrlAuth(1);//忽略权限，不收费
            generateShortUrlDto.setMiddlePageDomainId(domain);
            UzaiRespVo<String> uzaiRespVo = uzaiTurnlinkFeignService.generateShortUrl(generateShortUrlDto);
            logger.info("---发送朋友圈[今日合集]访问地址转成短链接---dto={},result={}",JSONObject.toJSONString(generateShortUrlDto), JSONObject.toJSONString(uzaiRespVo));
            if(uzaiRespVo != null && uzaiRespVo.getCode() == 200) {
                //获取生成的短链接
                middPageUrl = uzaiRespVo.getData();
                //短链接为空，则不替换[今日合集]
                if (StringUtils.isNotBlank(middPageUrl)) {
                    content = content.replace("[今日合集]", middPageUrl);
                    comment_new = comment_new.replace("[今日合集]", middPageUrl);
                }else{
                    logger.error(JSONObject.toJSONString(new BizLog(LogBizTypeEnum.CONSOLE_PYQ_SEND_AUTO_VALUE,
                            pyqAutoConfig.getMerId(), device.getRecvmsgType(), device.getId(),
                            "",0L,
                            "发送朋友圈，[今日合集]变量访问地址转成短链接失败！")));
                }
            }
        }

        //短语替换
        if(StringUtils.isNotBlank(pyqAutoConfig.getReplaceOld())){
            content = content.replace(pyqAutoConfig.getReplaceOld(), pyqAutoConfig.getReplaceNew());
            comment_new = comment_new.replace(pyqAutoConfig.getReplaceOld(), pyqAutoConfig.getReplaceNew());
        }

        //判断是否有今日合集变量，如果有，则购买连接需要拼今日合集参数-修改成不管有没有今日合集变量，购买连接中都有今日合集
        //if(todaySendListFlag){
        if(true){
            //先转链-不生成短链接
            TurnlinkDto turnlinkDto = new TurnlinkDto();
            turnlinkDto.setMerId(pyqJobDetail.getMerId());
            turnlinkDto.setPlatform(pyqJobDetail.getPlatform());
            turnlinkDto.setCouponId(pyqJobDetail.getCouponId());
            turnlinkDto.setDevicePlanId(pyqAutoConfig.getDevicePlanId());
            turnlinkDto.setItemId(pyqJobDetail.getItemId());
            if(StringUtils.isNotBlank(pyqLlyGoodsVo.getItemUrl())){
                turnlinkDto.setUrl(pyqLlyGoodsVo.getItemUrl());
            }
            turnlinkDto.setDeviceUniqueId(device.getId());
            turnlinkDto.setGenerateShortUrl(0);//不生成短链接，拼凑今日合集参数之后在生成短链接
            //老林商品库忽略短链接授权
            turnlinkDto.setIgnoreShortUrlAuth(1);//忽略，不收费
            SimpleTurnlinkVo simpleTurnlinkVo = getGoodInfo(turnlinkDto);
            //判断是否有购买链接和淘口令，如果没有，则不发朋友圈
            if(StringUtils.isBlank(simpleTurnlinkVo.getBuyUrl())){
                //第二次调用转链，如果还异常，则不发送
                simpleTurnlinkVo = getGoodInfo(turnlinkDto);
                if(StringUtils.isBlank(simpleTurnlinkVo.getBuyUrl())){
                    logger.error(JSONObject.toJSONString(new BizLog(LogBizTypeEnum.CONSOLE_PYQ_SEND_AUTO_VALUE,
                            pyqJobDetail.getMerId(), device.getRecvmsgType(), device.getId(),
                            "",0L,
                            "转链失败,未获取到购买链接")));
                    //发送失败
                    pyqJobDetail.setStatus(PyqJobDetailStatusEnum.SENDFAIL.getValue());
                    if(StringUtils.isNotBlank(simpleTurnlinkVo.getReturnMsg())){
                        pyqJobDetail.setFailMsg(simpleTurnlinkVo.getReturnMsg());
                    }else{
                        pyqJobDetail.setFailMsg("转链失败,未获取到购买链接");
                    }

                    //判断是否是商品问题，如果是则需要发送记录
                    if("未参加商品推广".equals(simpleTurnlinkVo.getReturnMsg()) || "商品信息有误".equals(simpleTurnlinkVo.getReturnMsg())) {
                        //插入自动发送记录表中
                        PyqAutoSend pyqAutoSend = new PyqAutoSend();
                        pyqAutoSend.setId(IdWorker.getId());
                        pyqAutoSend.setMerId(pyqAutoConfig.getMerId());
                        pyqAutoSend.setAutoConfigId(pyqAutoConfig.getId());
                        pyqAutoSend.setDeviceType(DeviceTypeEnum.DT_PC_WECHAT.getKey());
                        pyqAutoSend.setDeviceUniqueId(device.getId());
                        pyqAutoSend.setSendTime(pyqAutoConfig.getSendTime());
                        pyqAutoSend.setCreateTime(now);
                        pyqAutoSend.setUpdateTime(now);
                        pyqAutoSend.setType(pyqAutoConfig.getType());
                        pyqAutoSend.setGoodsid(pyqLlyGoodsVo.getId());
                        pyqAutoSendMapper.insertSelective(pyqAutoSend);
                    }

                    return pyqJobDetail;
                }
            }

            //商品淘口令
            pyqJobDetail.setItemPwd(simpleTurnlinkVo.getBuyPwd());
            //设置打开淘宝url
            pyqJobDetail.setPwdShortUrl(simpleTurnlinkVo.getPwdShortUrl());

            if(Tools.getInteger(pyqJobDetail.getPlatform()).intValue() == 0) { //淘宝
                //购买连接此时为长连接，需要拼接今日合集参数，在申请短链接
                String buyUrl = simpleTurnlinkVo.getBuyUrl();
                //拼接今日合集参数
                buyUrl = buyUrl + String.format(uzaiConsoleSysConfig.getPyqBuyUrlAddTodaySendListPara(), pyqJobDetail.getId(), pyqJobDetail.getMerId());
                //拼接今日合集参数之后的购买链接生成短链接
                GenerateShortUrlDto generateShortUrlDto = new GenerateShortUrlDto();
                generateShortUrlDto.setMerId(pyqJobDetail.getMerId());
                generateShortUrlDto.setUrl(buyUrl);
                generateShortUrlDto.setIgnoreShortUrlAuth(1);//忽略生成短链接权限，不收费
                UzaiRespVo<String> uzaiRespVo = uzaiTurnlinkFeignService.generateShortUrl(generateShortUrlDto);
                logger.info("---拼接今日合集参数之后商品长连接申请短链接接口--para={},reuslt={}", JSONObject.toJSONString(generateShortUrlDto), JSONObject.toJSONString(uzaiRespVo));
                //申请短链接成功，则替换购买连接和淘口令
                if(uzaiRespVo != null && uzaiRespVo.getCode() == 200 && StringUtils.isNotBlank(uzaiRespVo.getData())){
                    String shortBuyUrl = Tools.getStr(uzaiRespVo.getData());
                    content = content.replace("[购买链接]",shortBuyUrl)
                            .replace("[淘口令]",Tools.getStr(simpleTurnlinkVo.getBuyPwd()));
                    pyqJobDetail.setContent(content);

                    //评论内容替换变量
                    comment_new = comment_new.replace("[购买链接]", shortBuyUrl)
                            .replace("[淘口令]",Tools.getStr(simpleTurnlinkVo.getBuyPwd()));
                    pyqJobDetail.setCommentContent(comment_new);
                }else{//申请短链接失败
                    logger.error(JSONObject.toJSONString(new BizLog(LogBizTypeEnum.CONSOLE_PYQ_SEND_AUTO_VALUE,
                            pyqJobDetail.getMerId(), device.getRecvmsgType(), device.getId(),
                            "",0L,
                            "----未获取到短链接--")));
                    //发送失败
                    pyqJobDetail.setStatus(PyqJobDetailStatusEnum.SENDFAIL.getValue());
                    pyqJobDetail.setFailMsg(simpleTurnlinkVo.getReturnMsg());
                    return pyqJobDetail;
                }
            }else{//其他商品
                String shortBuyUrl = Tools.getStr(simpleTurnlinkVo.getBuyUrl());
                content = content.replace("[购买链接]",shortBuyUrl);
                pyqJobDetail.setContent(content);

                //评论内容替换变量
                comment_new = comment_new.replace("[购买链接]", shortBuyUrl);
                pyqJobDetail.setCommentContent(comment_new);
            }
        }else{//没有今日合集变量，则正常转链
            //先转链-生成短链接
            TurnlinkDto turnlinkDto = new TurnlinkDto();
            turnlinkDto.setMerId(pyqAutoConfig.getMerId());
            turnlinkDto.setPlatform(0); //精品库只支持淘宝
            turnlinkDto.setCouponId(pyqJobDetail.getCouponId());
            turnlinkDto.setDevicePlanId(pyqAutoConfig.getDevicePlanId());
            turnlinkDto.setItemId(pyqJobDetail.getItemId());
            if(StringUtils.isNotBlank(pyqLlyGoodsVo.getItemUrl())){
                turnlinkDto.setUrl(pyqLlyGoodsVo.getItemUrl());
            }
            turnlinkDto.setDeviceUniqueId(device.getId());
            turnlinkDto.setGenerateShortUrl(1); //生成短链接
            turnlinkDto.setIgnoreShortUrlAuth(1);//忽略，悠哉精品库商品不收费

            SimpleTurnlinkVo simpleTurnlinkVo = getGoodInfo(turnlinkDto);
            //淘口令为空，则不发朋友圈
            if(StringUtils.isBlank(simpleTurnlinkVo.getBuyUrl())){
                //第二次调用转链，如果还异常，则不发送
                simpleTurnlinkVo = getGoodInfo(turnlinkDto);
                if(StringUtils.isBlank(simpleTurnlinkVo.getBuyUrl())){
                    logger.error(JSONObject.toJSONString(new BizLog(LogBizTypeEnum.CONSOLE_PYQ_SEND_AUTO_VALUE,
                            pyqAutoConfig.getMerId(), device.getRecvmsgType(), device.getId(),
                            "",0L,
                            "转链失败，未获取到购买链接")));
                    //发送失败
                    pyqJobDetail.setStatus(PyqJobDetailStatusEnum.SENDFAIL.getValue());
                    if(StringUtils.isNotBlank(simpleTurnlinkVo.getReturnMsg())){
                        pyqJobDetail.setFailMsg(simpleTurnlinkVo.getReturnMsg());
                    }else{
                        pyqJobDetail.setFailMsg("转链失败,未获取到购买链接");
                    }

                    //判断是否是商品问题，如果是则需要发送记录
                    if("未参加商品推广".equals(simpleTurnlinkVo.getReturnMsg()) || "商品信息有误".equals(simpleTurnlinkVo.getReturnMsg())) {
                        //插入自动发送记录表中
                        PyqAutoSend pyqAutoSend = new PyqAutoSend();
                        pyqAutoSend.setId(IdWorker.getId());
                        pyqAutoSend.setMerId(pyqAutoConfig.getMerId());
                        pyqAutoSend.setAutoConfigId(pyqAutoConfig.getId());
                        pyqAutoSend.setDeviceType(DeviceTypeEnum.DT_PC_WECHAT.getKey());
                        pyqAutoSend.setDeviceUniqueId(device.getId());
                        pyqAutoSend.setSendTime(pyqAutoConfig.getSendTime());
                        pyqAutoSend.setCreateTime(now);
                        pyqAutoSend.setUpdateTime(now);
                        pyqAutoSend.setType(pyqAutoConfig.getType());
                        pyqAutoSend.setGoodsid(pyqLlyGoodsVo.getId());
                        pyqAutoSendMapper.insertSelective(pyqAutoSend);
                    }

                    return pyqJobDetail;
                }
            }
            //商品淘口令
            pyqJobDetail.setItemPwd(simpleTurnlinkVo.getBuyPwd());
            //设置打开淘宝url
            pyqJobDetail.setPwdShortUrl(simpleTurnlinkVo.getPwdShortUrl());
            //朋友圈内容替换变量
            content = content.replace("[购买链接]",Tools.getStr(simpleTurnlinkVo.getBuyUrl()))
                    .replace("[淘口令]",Tools.getStr(simpleTurnlinkVo.getBuyPwd()));
            pyqJobDetail.setContent(content);
            //评论内容替换变量
            comment_new = comment_new.replace("[购买链接]",Tools.getStr(simpleTurnlinkVo.getBuyUrl()))
                    .replace("[淘口令]",Tools.getStr(simpleTurnlinkVo.getBuyPwd()));
            pyqJobDetail.setCommentContent(comment_new);
        }

        //最后设置朋友圈明细发送中（正常的朋友圈）
        pyqJobDetail.setStatus(PyqJobDetailStatusEnum.NOSEND.getValue());//设置发送中状态
        return pyqJobDetail;

    }


    /**
     * 从评论列表中查找符合条件的评论
     *  contentType：0-文字评论；1-购买链接； 2-淘口令 ；3-抖音口令；4-快口令
     */
    private String getDescription(List<String> descriptionList, int contentType){
        if(descriptionList == null || descriptionList.size() == 0 ){
            return null;
        }
        //文字评论
        if(contentType == 0){
            for (String description : descriptionList) {
                if(StringUtils.isNotBlank(description)){
                    if(!description.contains("[购买链接]")
                            && !description.contains("[淘口令]")
                            && !description.contains("[抖音口令]")
                            && !description.contains("[快口令]")
                    ){
                        return description;
                    }
                }
            }
        }else if(contentType== 1){ //购买链接
            for (String description : descriptionList) {
                if(StringUtils.isNotBlank(description)){
                    if(description.contains("[购买链接]")){
                        return description;
                    }
                }
            }
        }else if(contentType== 2){ //淘口令
            for (String description : descriptionList) {
                if(StringUtils.isNotBlank(description)){
                    if(description.contains("[淘口令]")){
                        return description;
                    }
                }
            }
        }else if(contentType== 3){ //抖音口令
            for (String description : descriptionList) {
                if(StringUtils.isNotBlank(description)){
                    if(description.contains("[抖音口令]")){
                        return description;
                    }
                }
            }
        }else if(contentType== 4){ //快口令
            for (String description : descriptionList) {
                if(StringUtils.isNotBlank(description)){
                    if(description.contains("[快口令]")){
                        return description;
                    }
                }
            }
        }


        return null;
    }


    /**
     * 自动发送图文朋友圈商品明细
     * @author liuqi
     * @date 2021/8/25 11:38
     * @param pyqAutoConfig
     * @return null
     */
    private PyqJobDetail sendPyqJobDetailByCustomSync(PyqAutoConfig pyqAutoConfig, Long deviceUniqueId, Long pyqJobId, int now){
        Device device = deviceService.findDeviceInfoByDeviceUniqueId(deviceUniqueId, null, pyqAutoConfig.getMerId());
        if(device == null){
            return null;
        }

        Integer type = Tools.getInteger(pyqAutoConfig.getType());

        //赋值子任务明细
        PyqJobDetail pyqJobDetail = new PyqJobDetail() ;
        pyqJobDetail.setId(String.valueOf(IdWorker.getId()));
        pyqJobDetail.setVersion(0L);
        pyqJobDetail.setMerId(pyqAutoConfig.getMerId());
        pyqJobDetail.setJobId(pyqJobId);
        pyqJobDetail.setDeviceUniqueId(deviceUniqueId);
        pyqJobDetail.setDeviceType(device.getRecvmsgType());
        pyqJobDetail.setType(pyqAutoConfig.getType());
        pyqJobDetail.setPlatform(0);//淘宝
        pyqJobDetail.setSource(1);//发送来源（0手动发送；1自动发圈；2自动跟发）
        pyqJobDetail.setStartTime(pyqAutoConfig.getSendTime());
        pyqJobDetail.setSendTime(pyqAutoConfig.getSendTime());

        //图片
        List<String> imgList = new ArrayList<>();
        if(StringUtils.isNotBlank(pyqAutoConfig.getImgs())){
            try {
                imgList.addAll(JSONObject.parseArray(pyqAutoConfig.getImgs(), String.class));
            }catch (Exception e){

            }
        }

        if(imgList.size() > 9){
            imgList = imgList.subList(0, 9);
        }

        //2023-08-08 修改增加媒体信息
        List<FeedMedia> feedMediaList = new ArrayList();
        if(imgList != null && imgList.size() > 0){
            for (String img : imgList) {
                FeedMedia feedMedia = new FeedMedia();
                feedMedia.setUrl(img);
                feedMediaList.add(feedMedia);
            }
        }

        //2023-08-08 修改增加媒体信息
        pyqJobDetail.setAttachType(2);//图文
        pyqJobDetail.setFeedMediaList(Tools.getStrNull(JSONObject.toJSONString(feedMediaList)));
        pyqJobDetail.setPyqVideoNumber(null);
        pyqJobDetail.setImgs(null);  //新版朋友圈接口，img不存放任何东西

        pyqJobDetail.setCreateTime(now);
        pyqJobDetail.setUpdateTime(now);

        //朋友圈内容
        //朋友圈内容替换变量
        String content = Tools.getStr(pyqAutoConfig.getContent());

        //替换随机字符串
        content = MsgSplitUtil.replaceRandomStrArgs(content);
        //替换随机表情
        while (content.contains("[随机表情]")){
            content = content.replaceFirst("\\[随机表情\\]", Tools.getStr(EmojiUtil.getRandomEmoji()));
        }

        pyqJobDetail.setContent(content);

        //评论内容替换变量
        List<String> commentList = new ArrayList<>();

        //自动发圈任务自定义评论
        String commentContent = Tools.getStr(pyqAutoConfig.getCommentContent());

        //追加页面自定义评论
        List<String> commentContentList =  JSONArray.parseArray(commentContent, String.class);
        if(commentContentList != null && commentContentList.size() > 0){
            for(String demo : commentContentList){
                if(StringUtils.isNotBlank(demo)){
                    commentList.add(demo);
                }
            }
        }

        //去空评论
        commentList.removeIf(s -> StringUtils.isBlank(s));

        //新评论(商品自带的评论+任务配置的评论)
        String comment_new = JSONObject.toJSONString(commentList);

        //替换随机字符串
        comment_new = MsgSplitUtil.replaceRandomStrArgs(comment_new);

        //替换随机表情
        while (comment_new.contains("[随机表情]")){
            comment_new = comment_new.replaceFirst("\\[随机表情\\]", Tools.getStr(EmojiUtil.getRandomEmoji()));
        }
        pyqJobDetail.setCommentContent(comment_new);

        //关键词过滤
        String ignore = pyqAutoConfig.getIgnore();
        if(StringUtils.isNotBlank(ignore)){
            try {
                List<String> ignoreList = JSONObject.parseArray(ignore, String.class);
                if(ignoreList != null && ignoreList.size() > 0){
                    for (String ignoreKey : ignoreList){
                        if(content.contains(ignoreKey)){
                            return null;
                        }
                        if(comment_new.contains(ignoreKey)){
                            return null;
                        }
                    }
                }
            }catch (Exception e){

            }
        }

        //是否开启插入随机表情
        Integer emoji = Tools.getInteger(pyqAutoConfig.getEmoji());
        if(emoji.intValue() == 1){ //开启插入随机表情
            //朋友圈内容前后各插2个
            //content = EmojiUtil.getRandomEmoji() + EmojiUtil.getRandomEmoji() + content + EmojiUtil.getRandomEmoji() + EmojiUtil.getRandomEmoji();
            //朋友圈内容结尾插2个
            content = content + EmojiUtil.getRandomEmoji() + EmojiUtil.getRandomEmoji();

            pyqJobDetail.setContent(content);
            //评论前后各插一个
//            List<String> comment_newList_emoji = JSONObject.parseArray(comment_new, String.class);
//            if(comment_newList_emoji != null && comment_newList_emoji.size() > 0) {
//                //评论前后各插一个
//                //List<String> list1 = comment_newList_emoji.stream().map(s -> EmojiUtil.getRandomEmoji() + s + EmojiUtil.getRandomEmoji()).collect(Collectors.toList());
//                //评论结尾插一个
//                List<String> list1 = comment_newList_emoji.stream().map(s -> s + EmojiUtil.getRandomEmoji()).collect(Collectors.toList());
//                comment_new = JSONObject.toJSONString(list1);
//                pyqJobDetail.setCommentContent(comment_new);
//            }
        }



        List<PyqJobDetail> pyqJobDetailList = new ArrayList<>();
        pyqJobDetail.setStatus(PyqJobDetailStatusEnum.NOSEND.getValue());
        pyqJobDetailList.add(pyqJobDetail);

        try{
            int time1 = DateUtil.getNowTime();
            // UzaiRespVo<Boolean> uzaiRespVo = uzaiBroadcastFeignService.pyqMsgPush(pyqJobDetailList);
            //elasticsearchUtil.addData(JSONObject.parseObject(JSONObject.toJSONString(pyqJobDetail)), EsIndexName.UZAI_PYQ_JOB_DETAIL, pyqJobDetail.getId());
            String uzai_pyq_job_detail = merchantService.getMechantOtherEsIndexName(EsIndexName.UZAI_PYQ_JOB_DETAIL, pyqJobDetail.getMerId());
            //保存发送消息
            List<Map<String, Object>> list = BeanMapUtil.objectList2ListMap(pyqJobDetailList);
            boolean result = elasticsearchUtilGroupMsg.addDataBatch(list, uzai_pyq_job_detail);
            int time2 = DateUtil.getNowTime();
            logger.info("自动发送图文朋友圈明细完成---usetime={}, 机器人唯一id={}, result={}", time2-time1, pyqJobDetail.getDeviceUniqueId(), JSONObject.toJSONString(result));

        }catch (Exception e){
            return null;
        }
        return pyqJobDetail;

    }


    /**
     * 获取商品信息-简版转链
     * @author liuqi
     * @date 2021/8/13 11:38
     * @param turnlinkDto
     * @return null
     */
    private SimpleTurnlinkVo getGoodInfo(TurnlinkDto turnlinkDto){
        SimpleTurnlinkVo simpleTurnlinkVo = new SimpleTurnlinkVo();
        if(turnlinkDto.getPlatform() == null){
            logger.info("请选择平台");
            simpleTurnlinkVo.setReturnCode(ResponseCode.BUSINESS_EXCEPTION);
            simpleTurnlinkVo.setReturnMsg("请选择平台");
            return simpleTurnlinkVo;
        }

        if(turnlinkDto.getDevicePlanId() == null){
            logger.info("请选择设备方案");
            simpleTurnlinkVo.setReturnCode(ResponseCode.BUSINESS_EXCEPTION);
            simpleTurnlinkVo.setReturnMsg("请选择设备方案");
            return simpleTurnlinkVo;
        }

        PyqDevicePlan pyqDevicePlan = pyqDevicePlanMapper.selectById(turnlinkDto.getDevicePlanId(), turnlinkDto.getMerId());

        if(pyqDevicePlan == null){
            logger.info("该设备方案不存在");
            simpleTurnlinkVo.setReturnCode(ResponseCode.BUSINESS_EXCEPTION);
            simpleTurnlinkVo.setReturnMsg("该设备方案不存在");
            return simpleTurnlinkVo;
        }

        Long deviceUniqueId = turnlinkDto.getDeviceUniqueId();
        Long tbTokenId = null;
        String pid = "";
        Long jdTokenId = null;
        Long pddTokenId = null;
        Long vphTokenId = null;
        Long dyTokenId = null;
        Integer pddTokenType = null;
        Integer dyTokenType = null;
        Integer jdTokenType = null;
        Integer vphTokenType = null;

        //发送朋友圈的机器人列表
        List<Long> deviceUniqueIdList = null;
        if(pyqDevicePlan.getDeviceModel().intValue() == 0){ //发送部分机器人模式
            //验证发送机器人
            deviceUniqueIdList = JSONObject.parseArray(pyqDevicePlan.getDeviceInfo(), Long.class);
        }else if(pyqDevicePlan.getDeviceModel().intValue() ==1){ //全部机器人
            DeviceQuery deviceQuery = new DeviceQuery();
            deviceQuery.setMerId(turnlinkDto.getMerId());
            deviceQuery.setDeviceType(pyqDevicePlan.getDeviceType());
            Page<Device> page = deviceService.findDevicePage(deviceQuery);
            if(page != null && page.getRecords() != null && page.getRecords().size() > 0){
                deviceUniqueIdList = new ArrayList<>();
                for (Device device : page.getRecords()){
                    deviceUniqueIdList.add(device.getId());
                }
            }
        }

        if(deviceUniqueIdList == null || deviceUniqueIdList.size() == 0){
            logger.info("该设备方案未选择机器人");
            simpleTurnlinkVo.setReturnCode(ResponseCode.BUSINESS_EXCEPTION);
            simpleTurnlinkVo.setReturnMsg("该设备方案未选择机器人");
            return simpleTurnlinkVo;
        }

        //默认机器人为空，则未指定，则指定配置方案中的默认第一个机器人
        if(deviceUniqueId == null){
            deviceUniqueId = deviceUniqueIdList.get(0);
        }

        Device device = deviceService.findDeviceInfoByDeviceUniqueId(deviceUniqueId, pyqDevicePlan.getDeviceType(), turnlinkDto.getMerId());
        if(device == null ){
            logger.info("请求商品转链-机器人id为空");
            simpleTurnlinkVo.setReturnCode(ResponseCode.BUSINESS_EXCEPTION);
            simpleTurnlinkVo.setReturnMsg("请求商品转链-机器人id为空");
            return simpleTurnlinkVo;
        }

        if(pyqDevicePlan.getTokenType() != null && pyqDevicePlan.getTokenType().intValue() == 1){ //自己设置联盟
            JSONObject jsonObjectToken = JSONObject.parseObject(pyqDevicePlan.getTokenInfo());
            if(jsonObjectToken != null){
                //淘宝token
                JSONObject tbTokenJsonObject  = jsonObjectToken.getJSONObject("tbToken");
                if(tbTokenJsonObject != null){
                    tbTokenId = tbTokenJsonObject.getLong("tokenId");
                    pid = tbTokenJsonObject.getString("pid");
                }
                //京东token
                JSONObject jdTokenJsonObject  = jsonObjectToken.getJSONObject("jdToken");
                if(jdTokenJsonObject != null){
                    jdTokenId = jdTokenJsonObject.getLong("tokenId");
                    jdTokenType = jdTokenJsonObject.getInteger("type");
                }
                //拼多多token
                JSONObject pddTokenJsonObject  = jsonObjectToken.getJSONObject("pddToken");
                if(pddTokenJsonObject != null){
                    pddTokenId = pddTokenJsonObject.getLong("tokenId");
                    pddTokenType = pddTokenJsonObject.getInteger("type");
                }
                //唯品会token
                JSONObject vphTokenJsonObject  = jsonObjectToken.getJSONObject("vphToken");
                if(vphTokenJsonObject != null){
                    vphTokenId = vphTokenJsonObject.getLong("tokenId");
                    vphTokenType = vphTokenJsonObject.getInteger("type");
                }
                //抖音token
                JSONObject dyTokenJsonObject  = jsonObjectToken.getJSONObject("dyToken");
                if(dyTokenJsonObject != null){
                    dyTokenId = dyTokenJsonObject.getLong("tokenId");
                    dyTokenType = dyTokenJsonObject.getInteger("type");
                }
            }
        }else{ //默认从机器人中获取
            ConfigPlan configPlan = configPlanMapper.selectById(device.getConfigId(), device.getMerId());
            if(configPlan != null){

                //淘宝暂时不走机器人配置方案中联盟转链，淘宝商品走导购联盟
                if(false){
                    JSONObject jsonObject_tb = JSONObject.parseObject(configPlan.getTbAccountId());
                    if(jsonObject_tb != null) {
                        JSONArray jsonArray = jsonObject_tb.getJSONArray("tokens");
                        if (jsonArray != null && jsonArray.size() > 0) {
                            JSONObject jsonObject = (JSONObject) jsonArray.get(0);
                            String tokenIds = jsonObject.getString("tokenIds");
                            List<Long> tokenList = JSONObject.parseArray(tokenIds, Long.class);
                            if (tokenList != null && tokenList.size() > 0) {
                                tbTokenId = tokenList.get(0);
                                TbToken tbToken = tbTokenMapper.selectById(tbTokenId, turnlinkDto.getMerId());
                                if (tbToken != null) {
                                    pid = tbToken.getDefPid();
                                }
                            }
                        }
                    }
                }

                //京东token
                JSONObject jsonObject_jd = null;
                jdTokenType = configPlan.getJdAccountType();
                if(jdTokenType != null && jdTokenType.intValue() == 1){ //推老板共享联盟
                    jsonObject_jd = JSONObject.parseObject(configPlan.getTlbJdAccountId());
                }else{ //拼多多联盟
                    jsonObject_jd = JSONObject.parseObject(configPlan.getJdAccountId());
                }
                if(jsonObject_jd != null) {
                    JSONArray jsonArray = jsonObject_jd.getJSONArray("tokens");
                    if (jsonArray != null && jsonArray.size() > 0) {
                        JSONObject jsonObject = (JSONObject) jsonArray.get(0);
                        String tokenIds = jsonObject.getString("tokenIds");
                        List<Long> tokenList = JSONObject.parseArray(tokenIds, Long.class);
                        if (tokenList != null && tokenList.size() > 0) {
                            jdTokenId = tokenList.get(0);
                        }
                    }
                }

                //唯品会token
                JSONObject jsonObject_vph;
                vphTokenType = configPlan.getVphAccountType();
                if(vphTokenType != null && vphTokenType.intValue() == 1){ //推老板共享联盟
                    jsonObject_vph = JSONObject.parseObject(configPlan.getTlbVphAccountId());
                }else{ //拼多多联盟
                    jsonObject_vph = JSONObject.parseObject(configPlan.getVphAccountId());
                }
                if(jsonObject_vph != null) {
                    JSONArray jsonArray = jsonObject_vph.getJSONArray("tokens");
                    if (jsonArray != null && jsonArray.size() > 0) {
                        JSONObject jsonObject = (JSONObject) jsonArray.get(0);
                        String tokenIds = jsonObject.getString("tokenIds");
                        List<Long> tokenList = JSONObject.parseArray(tokenIds, Long.class);
                        if (tokenList != null && tokenList.size() > 0) {
                            vphTokenId = tokenList.get(0);
                        }
                    }
                }

                //拼多多token
                JSONObject jsonObject_pdd = null;
                pddTokenType = configPlan.getPddAccountType();
                if(configPlan.getPddAccountType() != null && configPlan.getPddAccountType().intValue() == 1){ //推老板共享联盟
                    jsonObject_pdd = JSONObject.parseObject(configPlan.getTlbPddAccountId());
                }else{ //拼多多联盟
                    jsonObject_pdd = JSONObject.parseObject(configPlan.getPddAccountId());
                }
                if(jsonObject_pdd != null) {
                    JSONArray jsonArray = jsonObject_pdd.getJSONArray("tokens");
                    if (jsonArray != null && jsonArray.size() > 0) {
                        JSONObject jsonObject = (JSONObject) jsonArray.get(0);
                        String tokenIds = jsonObject.getString("tokenIds");
                        List<Long> tokenList = JSONObject.parseArray(tokenIds, Long.class);
                        if (tokenList != null && tokenList.size() > 0) {
                            pddTokenId = tokenList.get(0);
                        }
                    }
                }

                //抖音token
                JSONObject jsonObject_dy = null;
                dyTokenType = configPlan.getDyAccountType();
                if(configPlan.getDyAccountType() != null && configPlan.getDyAccountType().intValue() == 1){ //推老板共享联盟
                    jsonObject_dy = JSONObject.parseObject(configPlan.getTlbDyAccountId());
                }else{ //拼多多联盟
                    jsonObject_dy = JSONObject.parseObject(configPlan.getDyAccountId());
                }
                if(jsonObject_dy != null) {
                    JSONArray jsonArray = jsonObject_dy.getJSONArray("tokens");
                    if (jsonArray != null && jsonArray.size() > 0) {
                        JSONObject jsonObject = (JSONObject) jsonArray.get(0);
                        String tokenIds = jsonObject.getString("tokenIds");
                        List<Long> tokenList = JSONObject.parseArray(tokenIds, Long.class);
                        if (tokenList != null && tokenList.size() > 0) {
                            dyTokenId = tokenList.get(0);
                        }
                    }
                }
            }
        }

        if(StringUtils.isBlank(turnlinkDto.getItemId())){
            simpleTurnlinkVo.setReturnCode(ResponseCode.BUSINESS_EXCEPTION);
            simpleTurnlinkVo.setReturnMsg("缺少商品链接、商品id、淘口令等信息");
            return simpleTurnlinkVo;
        }

        SimpleTurnLinkDto simpleTurnLinkDto = new  SimpleTurnLinkDto();
        if(StringUtils.isNotBlank(turnlinkDto.getUrl())){
            simpleTurnLinkDto.setUrl(turnlinkDto.getUrl());
        }
        simpleTurnLinkDto.setMerId(turnlinkDto.getMerId());
        simpleTurnLinkDto.setDeviceUniqueId(deviceUniqueId);
        simpleTurnLinkDto.setDeviceType(device.getRecvmsgType());
        simpleTurnLinkDto.setCouponId(turnlinkDto.getCouponId());
        simpleTurnLinkDto.setBizSceneId(turnlinkDto.getBizSceneId());
        simpleTurnLinkDto.setGenerateShortUrl(turnlinkDto.getGenerateShortUrl());
        simpleTurnLinkDto.setMiddlePageDomainId(pyqDevicePlan.getDomain());
        simpleTurnLinkDto.setIgnoreShortUrlAuth(turnlinkDto.getIgnoreShortUrlAuth());
        simpleTurnLinkDto.setChannel(OrderSourceEnum.WECHAT_PYQ.getId());//微信朋友圈

        UzaiRespVo<SimpleTurnlinkVo> uzaiRespVo = null;
        if(PlatformTypeEnum.PT_TAOBAO.getId().intValue() == turnlinkDto.getPlatform().intValue()){ //淘宝
            if(tbTokenId == null) { //设备方案未配置淘宝联盟id
                logger.error(JSONObject.toJSONString(new BizLog(LogBizTypeEnum.CONSOLE_PYQ_SEND_AUTO_VALUE,
                        pyqDevicePlan.getMerId(), device.getRecvmsgType(), device.getId(),
                        "", 0L,
                        "朋友圈-设备方案未配置淘宝联盟")));
                //系统设置错误
                AlarmMsgFeignDto alarmMsgFeignDto = new AlarmMsgFeignDto();
                alarmMsgFeignDto.setMerId(device.getMerId());
                alarmMsgFeignDto.setType(SysMsgTypeEnum.SYS_SET_ERR.getValue()); //系统设置错误
                alarmMsgFeignDto.setDeviceUniqueId(null);
                alarmMsgFeignDto.setDeviceType(null);
                //消息
                JSONObject ext = new JSONObject();
                ext.put("content", "朋友圈-设备方案未配置淘宝联盟");
                alarmMsgFeignDto.setExt(ext.toJSONString());
//                UzaiRespVo uzaiRespVo_alarm = uzaiBroadcastFeignService.sysMsgPush(alarmMsgFeignDto);
//                logger.info("---发送系统设置错误报警--para={}, result={}", JSONObject.toJSONString(alarmMsgFeignDto), JSONObject.toJSONString(uzaiRespVo_alarm));

                //2024-01-09修改成直接发送MQ
                noticeMsgPushProducerService.sendSysAlarmMsgAsync(alarmMsgFeignDto);

                simpleTurnlinkVo.setReturnCode(ResponseCode.BUSINESS_EXCEPTION);
                simpleTurnlinkVo.setReturnMsg("设备方案未配置淘宝联盟");
                return simpleTurnlinkVo;
            }else{
                int tbQueryType = RegularUtil.getTbQueryType(turnlinkDto.getItemId());
                if(tbQueryType == 1){
                    simpleTurnLinkDto.setUrl(turnlinkDto.getItemId());
                }else if(tbQueryType == 2){
                    simpleTurnLinkDto.setItemId(turnlinkDto.getItemId());
                }else if(tbQueryType == 3){
                    simpleTurnLinkDto.setPwd(turnlinkDto.getItemId());
                }else{
                    simpleTurnlinkVo.setReturnCode(ResponseCode.BUSINESS_EXCEPTION);
                    simpleTurnlinkVo.setReturnMsg("未识别到商品信息");
                    return simpleTurnlinkVo;
                }
                simpleTurnLinkDto.setTokenId(tbTokenId);
                simpleTurnLinkDto.setPid(pid);
                uzaiRespVo = uzaiTurnlinkFeignService.tbTurnlinkSimple(simpleTurnLinkDto);
                logger.info("---调用淘宝转链- 参数={}，返回结果={}",JSONObject.toJSONString(simpleTurnLinkDto),JSONObject.toJSONString(uzaiRespVo));
            }
        }else if(PlatformTypeEnum.PT_JD.getId().intValue() == turnlinkDto.getPlatform().intValue()){ //京东
            if(jdTokenId == null){ //发单设备方案未配置京东联盟id
                logger.error(JSONObject.toJSONString(new BizLog(LogBizTypeEnum.CONSOLE_PYQ_SEND_AUTO_VALUE,
                        pyqDevicePlan.getMerId(), device.getRecvmsgType(), device.getId(),
                        "",0L,
                        "朋友圈-设备方案未配置京东联盟")));
                //系统设置错误
                AlarmMsgFeignDto alarmMsgFeignDto = new AlarmMsgFeignDto();
                alarmMsgFeignDto.setMerId(device.getMerId());
                alarmMsgFeignDto.setType(SysMsgTypeEnum.SYS_SET_ERR.getValue()); //系统设置错误
                alarmMsgFeignDto.setDeviceUniqueId(null);
                alarmMsgFeignDto.setDeviceType(null);
                //消息
                JSONObject ext = new JSONObject();
                ext.put("content", "朋友圈-设备方案未配置京东联盟");
                alarmMsgFeignDto.setExt(ext.toJSONString());
//                UzaiRespVo uzaiRespVo_alarm = uzaiBroadcastFeignService.sysMsgPush(alarmMsgFeignDto);
//                logger.info("---发送系统设置错误报警--para={}, result={}", JSONObject.toJSONString(alarmMsgFeignDto), JSONObject.toJSONString(uzaiRespVo_alarm));

                //2024-01-09修改成直接发送MQ
                noticeMsgPushProducerService.sendSysAlarmMsgAsync(alarmMsgFeignDto);

                simpleTurnlinkVo.setReturnCode(ResponseCode.BUSINESS_EXCEPTION);
                simpleTurnlinkVo.setReturnMsg("设备方案未配置京东联盟");
                return simpleTurnlinkVo;

            }else{
                //判断输入得是商品id还是商品链接
                if(turnlinkDto.getItemId().contains("http")){//商品链接
                    simpleTurnLinkDto.setUrl(turnlinkDto.getItemId());
                }else{
                    simpleTurnLinkDto.setItemId(turnlinkDto.getItemId());
                }
                simpleTurnLinkDto.setTokenId(jdTokenId);
                simpleTurnLinkDto.setJdTokenType(jdTokenType);
                uzaiRespVo = uzaiTurnlinkFeignService.jdTurnlinkSimple(simpleTurnLinkDto);

                logger.info("---调用京东转链- 参数={}，返回结果={}",JSONObject.toJSONString(simpleTurnLinkDto),JSONObject.toJSONString(uzaiRespVo));
            }
        }else if(PlatformTypeEnum.PT_PDD.getId().intValue() == turnlinkDto.getPlatform().intValue()){ //拼多多
            if(pddTokenId == null){ //发单设备方案未配置拼多多联盟id
                logger.error(JSONObject.toJSONString(new BizLog(LogBizTypeEnum.CONSOLE_PYQ_SEND_AUTO_VALUE,
                        pyqDevicePlan.getMerId(), device.getRecvmsgType(), device.getId(),
                        "",0L,
                        "朋友圈-设备方案未配置拼多多联盟")));

                //系统设置错误
                AlarmMsgFeignDto alarmMsgFeignDto = new AlarmMsgFeignDto();
                alarmMsgFeignDto.setMerId(device.getMerId());
                alarmMsgFeignDto.setType(SysMsgTypeEnum.SYS_SET_ERR.getValue()); //系统设置错误
                alarmMsgFeignDto.setDeviceUniqueId(null);
                alarmMsgFeignDto.setDeviceType(null);
                //消息
                JSONObject ext = new JSONObject();
                ext.put("content", "朋友圈-设备方案未配置拼多多联盟");
                alarmMsgFeignDto.setExt(ext.toJSONString());
//                UzaiRespVo uzaiRespVo_alarm = uzaiBroadcastFeignService.sysMsgPush(alarmMsgFeignDto);
//                logger.info("---发送系统设置错误报警--para={}, result={}", JSONObject.toJSONString(alarmMsgFeignDto), JSONObject.toJSONString(uzaiRespVo_alarm));

                //2024-01-09修改成直接发送MQ
                noticeMsgPushProducerService.sendSysAlarmMsgAsync(alarmMsgFeignDto);

                simpleTurnlinkVo.setReturnCode(ResponseCode.BUSINESS_EXCEPTION);
                simpleTurnlinkVo.setReturnMsg("设备方案未配置拼多多联盟");
                return simpleTurnlinkVo;

            }else{
                //优先采用商品url进行转链，如果url为空，则在判断商品id进行转链（因为商品id转链不能参与千万补贴活动）
                if(StringUtils.isNotBlank(turnlinkDto.getUrl())){
                    simpleTurnLinkDto.setUrl(turnlinkDto.getUrl());
                }else{
                    if(turnlinkDto.getItemId().contains("http")){//商品链接
                        simpleTurnLinkDto.setUrl(turnlinkDto.getItemId());
                    }else{
                        simpleTurnLinkDto.setItemId(turnlinkDto.getItemId());
                    }
                }

                simpleTurnLinkDto.setTokenId(pddTokenId);
                simpleTurnLinkDto.setPddTokenType(pddTokenType);
                simpleTurnLinkDto.setUseZsUnitUrl(true);
                uzaiRespVo = uzaiTurnlinkFeignService.pddTurnlinkSimple(simpleTurnLinkDto);

                logger.info("---调用拼多多转链- 参数={}，返回结果={}",JSONObject.toJSONString(simpleTurnLinkDto),JSONObject.toJSONString(uzaiRespVo));
            }

        }else if(PlatformTypeEnum.PT_VPH.getId().intValue() == turnlinkDto.getPlatform().intValue()){ //唯品会
            if(vphTokenId == null){ //发单设备方案未配置唯品会联盟id
                logger.error(JSONObject.toJSONString(new BizLog(LogBizTypeEnum.CONSOLE_PYQ_SEND_AUTO_VALUE,
                        pyqDevicePlan.getMerId(), device.getRecvmsgType(), device.getId(),
                        "",0L,
                        "朋友圈-设备方案未配置唯品会联盟")));

                //系统设置错误
                AlarmMsgFeignDto alarmMsgFeignDto = new AlarmMsgFeignDto();
                alarmMsgFeignDto.setMerId(device.getMerId());
                alarmMsgFeignDto.setType(SysMsgTypeEnum.SYS_SET_ERR.getValue()); //系统设置错误
                alarmMsgFeignDto.setDeviceUniqueId(null);
                alarmMsgFeignDto.setDeviceType(null);
                //消息
                JSONObject ext = new JSONObject();
                ext.put("content", "朋友圈-设备方案未配置唯品会联盟");
                alarmMsgFeignDto.setExt(ext.toJSONString());
//                UzaiRespVo uzaiRespVo_alarm = uzaiBroadcastFeignService.sysMsgPush(alarmMsgFeignDto);
//                logger.info("---发送系统设置错误报警--para={}, result={}", JSONObject.toJSONString(alarmMsgFeignDto), JSONObject.toJSONString(uzaiRespVo_alarm));
                //2024-01-09修改成直接发送MQ
                noticeMsgPushProducerService.sendSysAlarmMsgAsync(alarmMsgFeignDto);

                simpleTurnlinkVo.setReturnCode(ResponseCode.BUSINESS_EXCEPTION);
                simpleTurnlinkVo.setReturnMsg("设备方案未配置唯品会联盟");
                return simpleTurnlinkVo;
            }else{
                //判断输入得是商品id还是商品链接
                if(turnlinkDto.getItemId().contains("http")){//商品链接
                    simpleTurnLinkDto.setUrl(turnlinkDto.getItemId());
                }else{
                    simpleTurnLinkDto.setItemId(turnlinkDto.getItemId());
                }
                simpleTurnLinkDto.setTokenId(vphTokenId);
                simpleTurnLinkDto.setVphTokenType(vphTokenType);
                uzaiRespVo =uzaiTurnlinkFeignService.vphTurnlinkSimple(simpleTurnLinkDto);
                logger.info("---调用唯品会转链- 参数={}，返回结果={}",JSONObject.toJSONString(simpleTurnLinkDto),JSONObject.toJSONString(uzaiRespVo));
            }
        }

        if(uzaiRespVo != null && uzaiRespVo.getCode() == 200 && uzaiRespVo.getData() != null){
            simpleTurnlinkVo = uzaiRespVo.getData();
            simpleTurnlinkVo.setReturnCode(uzaiRespVo.getCode());
            simpleTurnlinkVo.setReturnMsg(uzaiRespVo.getMsg());
        }else{
            if(StringUtils.isNotBlank(uzaiRespVo.getMsg())){
                simpleTurnlinkVo.setReturnCode(uzaiRespVo.getCode());
                simpleTurnlinkVo.setReturnMsg(uzaiRespVo.getMsg());
            }else{
                simpleTurnlinkVo.setReturnCode(ResponseCode.BUSINESS_EXCEPTION);
                simpleTurnlinkVo.setReturnMsg("转链微服务接口调用失败");
            }
            return simpleTurnlinkVo;
        }

        return simpleTurnlinkVo;
    }

    /**
     * 获取悠哉精品库商品
     * 查找悠哉精品库商品原则如下：
     * 1-查找优先级别商品
     * 2-查找普通级别商品，曝光量小于基础曝光量的商品（按照30天销售量从大到小排序，数值越大优先发送）
     * 3-查找普通级别商品，按照朋友圈转化率从大到小排序，数值越大优先发送(过滤掉第二步已经发送过的商品)
     * @author lucher
     * @date 2023/3/15 10:32
     * @param sendTime_new 发送时间
     * @param goodsIdList 已经发送过的商品id
     * @param baseExposureNum 曝光量
     * @return null
     */
    private PyqLlyGoodsVo getUzjpkGoods(PyqAutoConfig pyqAutoConfig, Long deviceUniqueId, Integer sendTime_new, List<Long> goodsIdList, int baseExposureNum){
        //发送商品
        PyqLlyGoodsVo pyqLlyGoodsVo = null;
        if(pyqLlyGoodsVo == null){
            //1-查找优先级别商品
            LlyGoodsPageDto llyGoodsPageDto = new LlyGoodsPageDto();
            llyGoodsPageDto.setCurrent(1);
            llyGoodsPageDto.setSize(5);
            llyGoodsPageDto.setOrderByField("id"); //id排序
            llyGoodsPageDto.setAsc(false); //降序
            llyGoodsPageDto.setPromotionTime(sendTime_new);
            llyGoodsPageDto.setGoodsIdExcludeList(goodsIdList);
            llyGoodsPageDto.setPriority(1); //优先商品
            llyGoodsPageDto.setStatus(2);  //商品在线
            String materialType = pyqAutoConfig.getMaterialType();
            if(StringUtils.isNotBlank(materialType)){
                //不同时包含2或者5，则传入参数，否则不传入参数
                if(!(materialType.contains("2") && materialType.contains("5"))){
                    materialType = materialType.replace("[","").replace("]","");
                    llyGoodsPageDto.setMaterialType(materialType);
                }
            }

            if(Tools.getInteger(pyqAutoConfig.getType()).intValue() == 3){ //悠哉精品库拼多多商品
                llyGoodsPageDto.setPlatform(1);
            }else{
                llyGoodsPageDto.setPlatform(0); //悠哉精品库淘宝商品
            }

            UzaiRespVo<Page<PyqLlyGoodsVo>> uzaiRespVo = uzaiBusinessFeignService.goodsSelectByPage(llyGoodsPageDto);
            //logger.info("--查询优先级别商品；机器人唯一id={}, para={}, result={}", deviceUniqueId, JSONObject.toJSONString(llyGoodsPageDto), JSONObject.toJSONString(uzaiRespVo));
            if(uzaiRespVo.getCode() == 200 && uzaiRespVo.getData() != null && uzaiRespVo.getData().getTotal() > 0){
                Page<PyqLlyGoodsVo> pyqLlyGoodsVoPage = uzaiRespVo.getData();
                List<PyqLlyGoodsVo> records = pyqLlyGoodsVoPage.getRecords();
                if(records != null && records.size() > 0){
                    //不启用随机商品，就启用第一个
                    if(Tools.getInteger(pyqAutoConfig.getRandomImg()).intValue() == 0){
                        pyqLlyGoodsVo = records.get(0);
                    }else if(Tools.getInteger(pyqAutoConfig.getRandomImg()).intValue() == 1) { //启用随机商品
                        //获取此数组内的随机对象
                        int random = RandomUtil.getRandomInt(0, records.size()-1);
                        pyqLlyGoodsVo = records.get(random);
                    }
                }
            }
        }


        //第一步未找到商品，则进行第二步
        // 2-查找普通级别商品，曝光量小于基础曝光量的商品（按照30天销售量从大到小排序，数值越大优先发送）
        if(pyqLlyGoodsVo == null){
            LlyGoodsPageDto llyGoodsPageDto = new LlyGoodsPageDto();
            llyGoodsPageDto.setCurrent(1);
            llyGoodsPageDto.setSize(5);
            llyGoodsPageDto.setExposureNumMax(baseExposureNum);
            llyGoodsPageDto.setOrderByField("total_30day_sales"); //按照30天销量排序
            llyGoodsPageDto.setAsc(false); //降序
            llyGoodsPageDto.setPromotionTime(sendTime_new);
            llyGoodsPageDto.setGoodsIdExcludeList(goodsIdList);
            llyGoodsPageDto.setPriority(0); //普通商品
            llyGoodsPageDto.setStatus(2); //商品在线
            String materialType = pyqAutoConfig.getMaterialType();
            if(StringUtils.isNotBlank(materialType)){
                //不同时包含2或者5，则传入参数，否则不传入参数
                if(!(materialType.contains("2") && materialType.contains("5"))){
                    materialType = materialType.replace("[","").replace("]","");
                    llyGoodsPageDto.setMaterialType(materialType);
                }
            }

            if(Tools.getInteger(pyqAutoConfig.getType()).intValue() == 3){ //悠哉精品库拼多多商品
                llyGoodsPageDto.setPlatform(1);
            }else{
                llyGoodsPageDto.setPlatform(0); //悠哉精品库淘宝商品
            }

            UzaiRespVo<Page<PyqLlyGoodsVo>> uzaiRespVo = uzaiBusinessFeignService.goodsSelectByPage(llyGoodsPageDto);

            //logger.info("--查找普通级别商品，曝光量小于基础曝光量的商品；机器人唯一id={}, para={}, result={}", deviceUniqueId, JSONObject.toJSONString(llyGoodsPageDto), JSONObject.toJSONString(uzaiRespVo));

            if(uzaiRespVo.getCode() == 200 && uzaiRespVo.getData() != null && uzaiRespVo.getData().getTotal() > 0) {
                Page<PyqLlyGoodsVo> pyqLlyGoodsVoPage = uzaiRespVo.getData();
                List<PyqLlyGoodsVo> records = pyqLlyGoodsVoPage.getRecords();
                if (records != null && records.size() > 0) {
                    //不启用随机商品，就启用第一个
                    if(Tools.getInteger(pyqAutoConfig.getRandomImg()).intValue() == 0){
                        pyqLlyGoodsVo = records.get(0);
                    }else if(Tools.getInteger(pyqAutoConfig.getRandomImg()).intValue() == 1) { //启用随机商品
                        //获取此数组内的随机对象
                        int random = RandomUtil.getRandomInt(0, records.size()-1);
                        pyqLlyGoodsVo = records.get(random);
                    }
                }
            }
        }

        //第二步未找到商品，则进行第三步
        //3-查找普通级别商品，按照朋友圈转化率从大到小排序，数值越大优先发送(过滤掉第二步已经发送过的商品)
        if(pyqLlyGoodsVo == null){
            LlyGoodsPageDto llyGoodsPageDto = new LlyGoodsPageDto();
            llyGoodsPageDto.setCurrent(1);
            llyGoodsPageDto.setSize(5);
            //llyGoodsPageDto.setExposureNumMin(baseExposureNum);
            llyGoodsPageDto.setOrderByField("wechat_moments_conversion_rate"); //按照朋友圈转化率排序
            llyGoodsPageDto.setAsc(false); //降序
            llyGoodsPageDto.setPromotionTime(sendTime_new);
            llyGoodsPageDto.setGoodsIdExcludeList(goodsIdList);
            llyGoodsPageDto.setPriority(0); //普通商品
            llyGoodsPageDto.setStatus(2); //商品在线
            String materialType = pyqAutoConfig.getMaterialType();
            if(StringUtils.isNotBlank(materialType)){
                //不同时包含2或者5，则传入参数，否则不传入参数
                if(!(materialType.contains("2") && materialType.contains("5"))){
                    materialType = materialType.replace("[","").replace("]","");
                    llyGoodsPageDto.setMaterialType(materialType);
                }
            }
            if(Tools.getInteger(pyqAutoConfig.getType()).intValue() == 3){ //悠哉精品库拼多多商品
                llyGoodsPageDto.setPlatform(1);
            }else{
                llyGoodsPageDto.setPlatform(0); //悠哉精品库淘宝商品
            }

            UzaiRespVo<Page<PyqLlyGoodsVo>> uzaiRespVo = uzaiBusinessFeignService.goodsSelectByPage(llyGoodsPageDto);

            //logger.info("--查找普通级别商品，按照朋友圈转化率从大到小排序；机器人唯一id={}, para={}, result={}", deviceUniqueId, JSONObject.toJSONString(llyGoodsPageDto), JSONObject.toJSONString(uzaiRespVo));

            if(uzaiRespVo.getCode() == 200 && uzaiRespVo.getData() != null && uzaiRespVo.getData().getTotal() > 0) {
                Page<PyqLlyGoodsVo> pyqLlyGoodsVoPage = uzaiRespVo.getData();
                List<PyqLlyGoodsVo> records = pyqLlyGoodsVoPage.getRecords();
                if (records != null && records.size() > 0) {
                    //不启用随机商品，就启用第一个
                    if(Tools.getInteger(pyqAutoConfig.getRandomImg()).intValue() == 0){
                        pyqLlyGoodsVo = records.get(0);
                    }else if(Tools.getInteger(pyqAutoConfig.getRandomImg()).intValue() == 1) { //启用随机商品
                        //获取此数组内的随机对象
                        int random = RandomUtil.getRandomInt(0, records.size()-1);
                        pyqLlyGoodsVo = records.get(random);
                    }
                }
            }
        }

        return pyqLlyGoodsVo;
    }

    /**
     * 获取悠友库商品圈商品
     * 查找悠哉精品库商品原则如下：
     * 1-查询还未发送的商品,按照商品主键id优先最先入库的
     * @author lucher
     * @date 2023/3/15 10:32
     * @param sendTime_new 发送时间
     * @param goodsIdMax 已经发送过的最大商品id
     * @param yzjxGoodsUserId 优友圈用户id
     * @return null
     */
    private PyqLlyGoodsVo getUzjpkGoodsByGoodsUser(PyqAutoConfig pyqAutoConfig, Long deviceUniqueId, Integer sendTime_new, Long goodsIdMax, Long yzjxGoodsUserId){

        PyqLlyGoodsVo pyqLlyGoodsVo = null;
        //发送商品
        LlyGoodsPageDto llyGoodsPageDto = new LlyGoodsPageDto();
        llyGoodsPageDto.setPromotionTime(sendTime_new);
        llyGoodsPageDto.setQueryStartTime(sendTime_new);
        llyGoodsPageDto.setIdMax(goodsIdMax);
        llyGoodsPageDto.setUser_id(yzjxGoodsUserId);

        String materialType = pyqAutoConfig.getMaterialType();
        if(StringUtils.isNotBlank(materialType)){
            //不同时包含2或者5，则传入参数，否则不传入参数
            if(!(materialType.contains("2") && materialType.contains("5"))){
                materialType = materialType.replace("[","").replace("]","");
                llyGoodsPageDto.setMaterialType(materialType);
            }
        }

        UzaiRespVo<PyqLlyGoodsVo> uzaiRespVo = uzaiBusinessFeignService.goodsSelectByNewest(llyGoodsPageDto);
        logger.info("--查找悠友圈商品；机器人唯一id={}, para={}, result={}", deviceUniqueId, JSONObject.toJSONString(llyGoodsPageDto), JSONObject.toJSONString(uzaiRespVo));
        if(uzaiRespVo.getCode() == 200 && uzaiRespVo.getData() != null){
            pyqLlyGoodsVo = uzaiRespVo.getData();
        }
        return pyqLlyGoodsVo;
    }

    /**
     * 未找到商品信息创建朋友圈明细
     * @author liuqi
     * @date 2021/8/25 11:38
     * @param pyqAutoConfig
     * @return null
     */
    private PyqJobDetail createPyqDetailByNoGoods(PyqAutoConfig pyqAutoConfig, Long deviceUniqueId, Long pyqJobId, Integer platform, int now){
        Device device = deviceService.findDeviceInfoByDeviceUniqueId(deviceUniqueId, null,pyqAutoConfig.getMerId());
        if(device == null){
            return null;
        }
        //赋值子任务明细
        PyqJobDetail pyqJobDetail = new PyqJobDetail() ;
        pyqJobDetail.setId(String.valueOf(IdWorker.getId()));
        pyqJobDetail.setVersion(0L);
        pyqJobDetail.setMerId(pyqAutoConfig.getMerId());
        pyqJobDetail.setJobId(pyqJobId);
        pyqJobDetail.setDeviceUniqueId(device.getId());
        pyqJobDetail.setDeviceType(device.getRecvmsgType());
        pyqJobDetail.setType(pyqAutoConfig.getType());
        pyqJobDetail.setCouponId(null); //优惠券金额
        pyqJobDetail.setCouponVal(null);
        pyqJobDetail.setPlatform(platform);
        pyqJobDetail.setSource(1);//发送来源（0手动发送；1自动发圈；2自动跟发）
        pyqJobDetail.setStartTime(pyqAutoConfig.getSendTime());
        pyqJobDetail.setSendTime(pyqAutoConfig.getSendTime());
        pyqJobDetail.setItemId(null);
        pyqJobDetail.setItemHeaderId(null);
        pyqJobDetail.setItemTailId(null);
        pyqJobDetail.setImgs(null);
        pyqJobDetail.setContent(null);
        pyqJobDetail.setCommentContent(null);
        pyqJobDetail.setCreateTime(now);
        pyqJobDetail.setUpdateTime(now);
        //发送失败
        pyqJobDetail.setStatus(PyqJobDetailStatusEnum.SENDFAIL.getValue());
        pyqJobDetail.setFailMsg("未找到商品");

        //发送朋友圈列表
        List<PyqJobDetail> pyqJobDetailList = new ArrayList<>();
        pyqJobDetailList.add(pyqJobDetail);
        //调用微服务发送朋友圈明细接口
        // UzaiRespVo<Boolean> uzaiRespVo = uzaiBroadcastFeignService.pyqMsgPush(pyqJobDetailList);
        //elasticsearchUtil.addData(JSONObject.parseObject(JSONObject.toJSONString(pyqJobDetail)), EsIndexName.UZAI_PYQ_JOB_DETAIL, pyqJobDetail.getId());
        String uzai_pyq_job_detail = merchantService.getMechantOtherEsIndexName(EsIndexName.UZAI_PYQ_JOB_DETAIL, pyqJobDetail.getMerId());
        //保存发送消息
        List<Map<String, Object>> list = BeanMapUtil.objectList2ListMap(pyqJobDetailList);
        boolean result = elasticsearchUtilGroupMsg.addDataBatch(list, uzai_pyq_job_detail);

        if(!result){ //保存失败
            logger.error(JSONObject.toJSONString(new BizLog(LogBizTypeEnum.CONSOLE_PYQ_SEND_AUTO_VALUE,
                    pyqAutoConfig.getMerId(), device.getRecvmsgType(), device.getId(),
                    "",0L,
                    "-调用自动发送朋友圈明细微服务接口失败")));
            //调用微服务保存朋友圈明细失败，则返回空明细
        }

        return pyqJobDetail;
    }

}
